Android video playback

Source: Internet
Author: User

Video Playback is more complex than audio playback. In addition to audio, you also need to consider a visual component. To solve this problem, Android provides a dedicated View Controller android. widget. videoview encapsulates the creation and initialization processes of mediaplayer. This widget can be used in any layout manager and provides many display options, including scaling and coloring. To implement the playback function, we need to create a videoview widget and set it to the content of the user interface, and then set the view path or
Uri and trigger the START () method.

   In addition to button controls, video playback also requires a frame for displaying videos. In this example, the videoview component is used to display the video content. Instead of creating our own button control, a mediacontroller is created to provide these buttons (if you need to create another button, you can also create one by yourself ).

Package video. Player. activties;

Import Android. App. activity;
Import android.net. Uri;
Import Android. OS. Bundle;
Import Android. widget. mediacontroller;
Import Android. widget. videoview;

Public class mainactivity extends activity {

Private videoview;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Videoview = (videoview) This. findviewbyid (R. Id. videoview );
Mediacontroller MC = new mediacontroller (this );
Videoview. setmediacontroller (MC );
Videoview. setvideopath ("/sdcard/music/test.mp4 ");
Videoview. requestfocus ();
Videoview. Start ();
}

}

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Videoview
Android: Id = "@ + ID/videoview"
Android: layout_width = "320dip"
Android: layout_height = "260dip"
> </Videoview>
</Linearlayout>

Related Article

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.