Explain how the Android app uses Videoview to achieve video playback _android

Source: Internet
Author: User

To play video through Videoview:
1, define the Videoview component in the interface layout file, or create the Videoview component in the program
2, call the Videoview of the following two methods to load the specified video
(1) Setvidepath (String path): Load the video represented by the path file
(2) Setvideouri (URI uri): Load the video corresponding to the URI
3, call the Videoview start (), Stop (), Psuse () method to control the video playback

Videoview is used in conjunction with the Mediacontroller class to allow developers to control playback and pausing without their own

Package Cn.com.chenzheng_java; 
Import android.app.Activity; 
Import Android.media.MediaPlayer; 
Import Android.os.Bundle; 
Import Android.util.Log; 
Import Android.widget.MediaController; 
Import Android.widget.VideoView; 
 
Import Android.widget.MediaController.MediaPlayerControl; 
    public class Videoactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) { 
    Super.oncreate (savedinstancestate); 
     
    Setcontentview (R.layout.video); 
    Videoview Videoview = (videoview) Findviewbyid (R.ID.VIDEOVIEW1); /*** * Associate the player with the previous audio or video file * Videoview.setvideouri (URI uri) * Videoview.setvideopath (String path) * 
     All of the above two methods are OK. 
     
    * * Videoview.setvideopath ("Data/yueding.mp3"); /** * W provides a controller to control its pause, playback ... 
     
    and other functions/Videoview.setmediacontroller (new Mediacontroller (this)); /** * Video or audio to the end of the trigger method */Videoview.setoncompletionlistener (new Mediaplayer.oncompletionlistener () { 
      @Override public void Oncompletion (MediaPlayer MP) {LOG.I ("notification", "complete"); 
     
    } 
    }); Videoview.setonerrorlistener (New Mediaplayer.onerrorlistener () {@Override public boolean onError (Me 
        Diaplayer MP, int what, int extra) {LOG.I ("notification", "error appearing in playback"); 
      return false; 
     
  } 
    }); 
 } 
}

Video.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= 
"http://schemas.android.com/apk/" Res/android " 
  android:layout_width=" match_parent "android:layout_height=" match_parent " 
  android:o" rientation= "Horizontal" > 
  <videoview android:layout_height= "match_parent" android:id= "@+id/videoView1" 
    android:layout_width= "wrap_content" ></VideoView> 
</LinearLayout> 

Of course, we can also play multimedia on the network.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.