Android Development Learning Audio Video-videoview

Source: Internet
Author: User

Videoview is actually a packaged component for playing video in the Android SDK, using the following steps:

1. Define the video component in the layout file;

2. Load the specified video using the following method:

1) Setvideopath (String path)

2) Setvideouri (URI Uri)

3. Call the start (), Stop (), and Pause () methods of video to control the playback.

Examples are as follows:

Layout file

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"><!--define Videoview play Video -<VideoviewAndroid:id= "@+id/video"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" /></LinearLayout>

Sample code, the following code can be used to implement video playback

Videoview =new File ("/mnt/sdcard/test.mp4"); if (Video.exists ()) {    Videoview.setvideopath (Video.getabsolutepath ());    Videoview.start ();}

If you want to implement a video playback effect with a control bar, you can use the following code

Videoview = (videoview) Findviewbyid (r.id.video); New Mediacontroller (Thisnew File ("/mnt/sdcard/test.mp4"); if (Video.exists ()) {    Videoview.setvideopath (Video.getabsolutepath ());
    // setting up Videoview to associate     with Mcontroller Videoview.setmediacontroller (Mcontroller);
    // setting up Mcontroller to associate     with Videoview Mcontroller.setmediaplayer (Videoview);
}

Effects such as:

Android Development Learning Audio Video-videoview

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.