Android Videoview Simple Playback video

Source: Internet
Author: User


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

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.