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 ){
}
}