1 PackageCom.example.myvideo2;2 3 ImportJava.io.File;4 5 Importandroid.app.Activity;6 ImportAndroid.net.Uri;7 ImportAndroid.os.Bundle;8 Importandroid.os.Environment;9 ImportAndroid.view.Menu;Ten ImportAndroid.view.MenuItem; One ImportAndroid.view.View; A ImportAndroid.widget.Button; - ImportAndroid.widget.MediaController; - ImportAndroid.widget.MediaController.MediaPlayerControl; the ImportAndroid.widget.VideoView; - /** - * Android Play Video - * @Describe: + * @package: Com.example.myvideo2 - * @authorshaobn + * @date 2015-9-14 a.m. 10:57:41 A */ at Public classMainactivityextendsActivityImplementsMediaPlayerControl { - PrivateVideoview Videoview; - PrivateMediacontroller Mediacontroller; - Privatebutton button; - @Override - protected voidonCreate (Bundle savedinstancestate) { in Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); toMediacontroller =NewMediacontroller (mainactivity. This); +Videoview = (videoview) This. Findviewbyid (r.id.videoview1); -Button = (Button) This. Findviewbyid (r.id.button1); the Videoview.setmediacontroller (mediacontroller); *Button.setonclicklistener (NewView.onclicklistener () { $ Panax Notoginseng @Override - Public voidOnClick (View arg0) { the //TODO auto-generated Method Stub + if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) { AFile file1 =environment.getexternalstoragedirectory (); theFile file2 =NewFile (File1, "/movies/video.mp4"); +Uri uri =Uri.fromfile (file2); - Videoview.setvideouri (URI); $ } $ } - }); - the } - @OverrideWuyi Public BooleanCanPause () { the //TODO auto-generated Method Stub - returnvideoview.canpause (); Wu } - @Override About Public BooleanCanseekbackward () { $ //TODO auto-generated Method Stub - returnVideoview.canseekbackward (); - } - @Override A Public BooleanCanseekforward () { + //TODO auto-generated Method Stub the returnVideoview.canseekforward (); - } $ @Override the Public intGetaudiosessionid () { the //TODO auto-generated Method Stub the return0; the } - @Override in Public intGetbufferpercentage () { the //TODO auto-generated Method Stub the return0; About } the @Override the Public intGetCurrentPosition () { the //TODO auto-generated Method Stub + return0; - } the @OverrideBayi Public intgetduration () { the //TODO auto-generated Method Stub the return0; - } - @Override the Public Booleanisplaying () { the //TODO auto-generated Method Stub the returnvideoview.isplaying (); the } - @Override the Public voidpause () { the //TODO auto-generated Method Stub the if(Videoview.isplaying ()) {94 videoview.pause (); the } the } the @Override98 Public voidSeekto (intarg0) { About //TODO auto-generated Method Stub - Videoview.seekto (arg0);101 }102 @Override103 Public voidstart () {104 //TODO auto-generated Method Stub the Videoview.start ();106 }107 108 109}
Implement playback of video files.
Android Play Video File