Android Play Video File

Source: Internet
Author: User

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

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.