Video Playback file Switching Based on videoview

Source: Internet
Author: User

Videoview is a media playback display and Control control provided by the Android system. Its structure is as follows:

Extends surfaceview

Implements mediacontroller. mediaplayercontrol

Java. Lang. Object
Bytes Android. View. View
  Bytes Android. View. surfaceview
    Bytes Android. widget. videoview


Surfaceview
Supports display, while mediaplayercontrol supports media control.
When playing a video file in eclair, the progress bar Slider of mediaplayercontrol is sometimes incomplete. You can modify
The layout file frameworks/base/CORE/RES/layout/media_controller.xml is used to achieve the desired effect.
Here, a movieview is implemented based on videoview, which supports playing the last and next videos. The following is the main code:


Public class movieview extends activity implements
Mediaplayer. onerrorlistener, mediaplayer. oncompletionlistener,
Mediaplayer. onpreparedlistener
{
@ Override
Public void oncreate (bundle icicle)
{
Super. oncreate (icicle );
Setcontentview (R. layout. movie_view );
Mvideoview = (videoview) findviewbyid (R. Id. surface_view );
Uri uri = getintent (). getdata ();
Mcurrent = getintent (). getintextra ("START", 0 );
Makecursor ();
Mvideoview. setonerrorlistener (this );
Mvideoview. setoncompletionlistener (this );
Mvideoview. setonpreparedlistener (this );
Mvideoview. setvideouri (URI );

Mmediacontroller = new mediacontroller (this, false );
Mmediacontroller. setprevnextlisteners (mnextlistener, mprevlistener );
Mvideoview. setmediacontroller (mmediacontroller );
Mvideoview. Start ();
}


Private void makecursor (){
String [] Cols = new string [] {
Mediastore. Video. Media. _ id,
Mediastore. Video. Media. title,
Mediastore. Video. Media. Data,
Mediastore. Video. Media. mime_type,
Mediastore. Video. Media. Artist
};
Contentresolver resolver = getcontentresolver ();
If (Resolver = NULL ){
System. Out. println ("resolver = NULL ");
} Else {

String msortorder = mediastore. Video. Media. Title + "collate Unicode ";
String mwhereclause = mediastore. Video. Media. Title + "! = ''";
Mcursor = resolver. Query (mediastore. Video. Media. external_content_uri,
Cols, mwhereclause, null, msortorder );

}
}

Private view. onclicklistener mnextlistener = new view. onclicklistener (){
Public void onclick (view v ){
Mcurrent = (mcurrent + 1) % mcursor. getcount ();
Mcursor. movetoposition (mcurrent );
Long id = mcursor. getlong (0 );
Uri uri = contenturis. withappendedid (mediastore. Video. Media. external_content_uri, ID );
Mvideoview. setvideouri (URI );
Mvideoview. Start ();
}

}
Private view. onclicklistener mprevlistener = new view. onclicklistener (){
Public void onclick (view v ){
/* Get Prev URI */
Mvideoview. setvideouri (URI );
Mvideoview. Start ();
}
}

@ Override
Public void onpause (){
Super. onpause ();
}

Public Boolean onerror (mediaplayer player, int arg1, int arg2 ){
}

Public void oncompletion (mediaplayer MP ){

}

Public void onprepared (mediaplayer MP ){
}
}

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.