Give Android videoview A file directory, you can directly play the video files in the tracker, now to play a video file with a phone shot and renamed Test.mp4 for example.
(1) You need to write a viedoview in the layout file :
<relativelayoutxmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context = "Com.example.videoview.MainActivity" > <videoview android:layout_width= "match_parent" android:layout _height= "Match_parent" android:id= "@+id/videoview"/> </RelativeLayout>
(2) do not forget to Add read/write external storage permissions to the Androidmanifest.xml file:
<uses-permissionandroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
(3) in Java code , set the file directory to Videoview and start playback:
public class mainactivity extends activity{ @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview ( R.layout.activity_main); videoview videoview = ( Videoview) findviewbyid (R.id.videoview); // obtains a path equal to :/storage/emulated/0/dcim file path = environment . Getexternalstoragepublicdirectory (ENVIRONMENT.DIRECTORY_DCIM); Stitching full path file f = new file (path, "/ Camera/test.mp4 "); // at this time F.getabsolutepath () =/storage/emulated/0/dcim//\camera/test.mp4 videoview.setvideopath (F.getabsolutepath ()); // start playing video videoview.start (); // videiview Focus // Videoview.requestfocus (); }}
above! In addition to the APP for a full range of detection, I will use this:www.ineice.com.
Android Videoview Simple Playback video