Preparations:
1. SurfaceView
Provides a dedicated drawing surface embedded inside of a view hierarchy. you can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen
2. SurfaceHolder
Abstract interface to someone holding a display surface. Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. This interface is typically available throughSurfaceView
Class.
3. MediaPlayer.
4. Playback file data source
Else ---------------------------------------------------------------------------------------------------------------------------------
<SurfaceView
Android: id = "@ + id/surfaceview"
Android: layout_width = "320px"
Android: layout_height = "240px"
/>
1. Obtain surfaceview -------- surfaceview = (surfaceview) findviewbyid (R. Id. surfaceview );
2. Obtain surfaceholder ------- surfaceholder = surfaceview. getholder ();
Surfaceholder. settype (surfaceholder. surface_type_push_buffers); // set the display content to be pushed from the outside.
Surfaceholder. addcallback (this); // a class instance is required to implement the surfaceholder. Callback interface.
3. instantiate a player mediaplayer = new mediaplayer ();
Mediaplayer. setdatasource ("http://www.bogotobogo.com/Video/sample.3gp"); // sets the data source
Mediaplayer. setdisplay (surfaceholder); // The settings are displayed in the surfaceview
Mediaplayer. setAudioStreamType (AudioManager. STREAM_MUSIC); // you can specify the stream format.
Mediaplayer. prepare ();
Mediaplayer. start ();