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.