Android Videoview Simple Playback video

Source: Internet
Author: User

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

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.