Android MediaPlayer Learning Notes

Source: Internet
Author: User

Life cycle:

650) this.width=650; "src=" Http://hi.csdn.net/attachment/201005/26/521376_1274912556IBBI.gif "alt=" 521376_ 1274912556ibbi.gif "/>

Note: Enter the playbackcompleted state after playback is complete.


Play Video:

public void Setdisplay (Surfaceholder sh)

SINCE:API Level 1

Sets the Surfaceholder for the video display. Whether it's surface holder or surface, you must set it if the video library requires it. When playing a video without calling this function or not calling Setsurface (Surface), only the audio will play. An empty surface holder or empty surface will cause just the audio to play.

Android.view.Surface:Handle onto a raw buffer that's being managed by the screen compositor.

android.view.SurfaceV Iew:

Surfaceholder is an abstract interface that controls surface, and you can control the size and formatting of your surface with surfaceholder, or modify the pixels on your surface, monitor changes in your surface, and more. Surfaceholder is a typical interface for Surfaceview.

Surfaceview relationship with surface:surface is the data (implementsparcelable) that manages the display, including the exchange that is stored in the data. And Surfaceview is showing the data to the screen.

Surfaceholder.callback is an interface for monitoring surface changes. It has the following methods:

public abstract void Surfacechanged (Surfaceholder holder, int. format, int width, int height) public abstract Voidsurfacecre Ated (Surfaceholder holder) public abstract voidsurfacedestroyed (Surfaceholder holder)



Code:

Public void oncreate (bundle savedinstancestate)  {         super.oncreate (savedinstancestate);         setcontentview ( R.layout.main);                  mediaplayer = new mediaplayer ();         nametext =  (EditText)  this.findviewbyid (r.id.filename);         surfaceView =  (Surfaceview)  this.findviewbyid (R.id.surfaceview);         //the video that is conveyed to Surfaceview, which is displayed directly on the screen, and does not maintain its own buffer          surfaceview.getholder (). SetType (surfaceholder.surface_type_push_buffers);         surfaceview.getholder (). Setfixedsize (176, 144);         surfaceview.gethOlder (). Setkeepscreenon (True);         surfaceview.getholder (). Addcallback (New surfacecallback ());    }              private final class SurfaceCallback implements  Callback{        public void surfacechanged (SurfaceHolder  holder, int format, int width, int height)  {         }        public void surfacecreated ( Surfaceholder holder)  {            if ( Position>0 && path!=null) {                 play (position);                 position = 0;            }         }        public void  surfacedestroyed (Surfaceholder holder)  {             if (Mediaplayer.isplaying ()) {                 position = mediaplayer.getcurrentposition ();                 mediaplayer.stop ();             }        }     }



Android MediaPlayer Learning Notes

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.