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