Android videoview usage routine

Source: Internet
Author: User

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>

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.