To the Android videoview a file directory, you can directly play the video files in the tracker, now to play a video file in advance with the phone and renamed Test.mp4 for example.
(1) You need to write a viedoview in the layout file:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context= "Com.example.videoview.MainActivity" >6 7 <Videoview8 Android:layout_width= "Match_parent"9 Android:layout_height= "Match_parent"Ten Android:id= "@+id/videoview" /> One A </Relativelayout>
(2) Do not forget to add read/write external storage permissions to the Androidmanifest.xml file:
1 < android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
(3) In Java code, set the file directory to Videoview and start playback:
1 PackageCom.example.videoview;2 3 ImportJava.io.File;4 5 Importandroid.app.Activity;6 ImportAndroid.os.Bundle;7 Importandroid.os.Environment;8 ImportAndroid.widget.VideoView;9 Ten Public classMainactivityextendsActivity { One A @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); the Setcontentview (r.layout.activity_main); - -Videoview Videoview =(Videoview) Findviewbyid (R.id.videoview); - + //the obtained path equals:/storage/emulated/0/dcim -File Path =Environment + . Getexternalstoragepublicdirectory (ENVIRONMENT.DIRECTORY_DCIM); A at //Stitching Full path -File f =NewFile (Path, "/camera/test.mp4"); - - //at this time the F.getabsolutepath () =/storage/emulated/0/dcim//\camera/test.mp4 - Videoview.setvideopath (F.getabsolutepath ()); - in //start playing video - Videoview.start (); to + //Videiview receives focus - //Videoview.requestfocus (); the } *}
Android Videoview Simple Playback video