Videoview is actually a packaged component for playing video in the Android SDK, using the following steps:
1. Define the video component in the layout file;
2. Load the specified video using the following method:
1) Setvideopath (String path)
2) Setvideouri (URI Uri)
3. Call the start (), Stop (), and Pause () methods of video to control the playback.
Examples are as follows:
Layout file
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"><!--define Videoview play Video -<VideoviewAndroid:id= "@+id/video"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" /></LinearLayout>
Sample code, the following code can be used to implement video playback
Videoview =new File ("/mnt/sdcard/test.mp4"); if (Video.exists ()) { Videoview.setvideopath (Video.getabsolutepath ()); Videoview.start ();}
If you want to implement a video playback effect with a control bar, you can use the following code
Videoview = (videoview) Findviewbyid (r.id.video); New Mediacontroller (Thisnew File ("/mnt/sdcard/test.mp4"); if (Video.exists ()) { Videoview.setvideopath (Video.getabsolutepath ());
// setting up Videoview to associate with Mcontroller Videoview.setmediacontroller (Mcontroller);
// setting up Mcontroller to associate with Videoview Mcontroller.setmediaplayer (Videoview);
}
Effects such as:
Android Development Learning Audio Video-videoview