I. xxxvideo. Java
Public class remotevideo extends activity {
Private string Path = "";
Private string texturl = "";
Private videoview mvideoview;
Private Static int I = 0;
Private int width;
Private int heigh;
Private dialog;
Private handler mhandler = new handler ();
Public void oncreate (bundle icicle ){
Super. oncreate (icicle );
Requestwindowfeature (window. feature_no_title );
Setrequestedorientation (activityinfo. screen_orientation_landscape );
Bundle bundle = This. getintent (). getextras ();
Displaymetrics dm = new displaymetrics ();
Getwindowmanager (). getdefaultdisplay (). getmetrics (DM );
Width = DM. widthpixels;
Heigh = DM. heightpixels;
Texturl = bundle. getstring ("url ");
If (width/heigh> 0)
{
Setcontentview (R. layout. videoview );
Path = bundle. getstring ("widthurl ");
Log. I ("MP4", "Heng" + path );
}
If (width/heigh = 0)
{
Setcontentview (R. layout. View );
Path = bundle. getstring ("heighturl ");
Log. I ("MP4", "Shu" + path );
}
Dialog = progressdialog. Show (this, "video loading...", "Please wait ");
Mvideoview = (videoview) findviewbyid (R. Id. surface_view );
Mvideoview. setvideopath (PATH );
Mediacontroller controller = new mediacontroller (this );
Mvideoview. setmediacontroller (Controller );
Mvideoview. requestfocus ();
Mvideoview. setonpreparedlistener (New onpreparedlistener (){
// @ Override
Public void onprepared (mediaplayer MP ){
Mvideoview. setbackgroundcolor (color. argb (0, 0,255, 0 ));
Dialog. Dismiss ();
}
});
Mvideoview. setoncompletionlistener (New oncompletionlistener (){
// @ Override
Public void oncompletion (mediaplayer MP ){
Toast. maketext (remotevideo. This, "video play finished! ", Toast. length_long)
. Show ();
}
});
Controller. setontouchlistener (New View. ontouchlistener (){
Public Boolean ontouch (view V, motionevent event ){
Return true;
}
});
}
@ Override
Protected void onresume (){
Super. onresume ();
Mvideoview. seekto (I );
Mvideoview. Start ();
}
@ Override
Protected void onstop (){
Super. onstop ();
Mvideoview. Pause ();
I = mvideoview. getcurrentposition ();
}
@ Override
Public Boolean onkeydown (INT keycode, keyevent event ){
If (keycode = keyevent. keycode_back & event. getrepeatcount () = 0 ){
Finish ();
Return true;
}
Return false;
}
}
Note:
1. videoview can receive and decode local and remote video sources;
2. mediacontroller is the control bar class of videoview;
3. Bundle gets the video path transmitted from intent;
Ii. videoview. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"
Android: gravity = "Left" Android: Orientation = "horizontal">
<Videoview Android: Id = "@ + ID/surface_view"
Android: layout_width = "176px" Android: layout_height = "132px"
Android: layout_gravity = "Left"/>
<Webview Android: Id = "@ + ID/web_openonline"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
</Linearlayout>