Video Player Development:
1. SurfaceView:
1. Display in unit time.
2. Internal dual-buffer mechanism:
3. directly operate the video memory of the video card, which is faster.
2. Specific steps for video playback development:
1. layout interface:
Android: layout_width = "fill_parent"
>
Android: orientation = "vertical">
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
>
Android: textSize = "20sp"/>
Android: id = "@ + id/et_path"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
>
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center_horizontal"
Android: orientation = "horizontal">
Android: id = "@ + id/play"
Android: layout_width = "0dip"
>
Android: layout_weight = "1"
Android: text = "play"/>
Android: id = "@ + id/pause"
Android: layout_width = "0dip"
Android: layout_height = "wrap_content"
>
Android: text = "paused"/>
Android: id = "@ + id/replay"
Android: layout_width = "0dip"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
>
Android: id = "@ + id/stop"
Android: layout_width = "0dip"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "stop"/>
// Controls for displaying videos:
Android: id = "@ + id/sv"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"/>
2. Video Player operations:
① Playback:
MediaPlayer>
MediaPlayer. setAudioStreamType (AudioManager. STREAM_MUSIC );
// Obtain the SurfaceView object:
SurfaceView>
// Obtain the SurfaceHolder object through SurfaceView
SurfaceHolder>
// Specify the control that displays the video to be played.
MediaPlayer. setDisplay (holder );
// Set the playback resource path, for example,/sdcard/oppo.3gp
MediaPlayer. setDataSource (path );
// Initialize the player:
Method 1: Synchronous:
MediaPlayer. prepare ();
Method 2: asynchronous:
MediaPlayer. prepareAsync (); // asynchronous preparation
// Set the listener for asynchronous preparation. After asynchronous preparation is complete, call the following method:
MediaPlayer. setOnPreparedListener (new OnPreparedListener (){
Public>
>
>
>
>
>
}
③ Stop:
Private>
// Obtain the current playback position
>
>
>
>
// Obtain the SurfaceHolder object through SurfaceView
SurfaceHolder>
// Specify the control that displays the video to be played.
MediaPlayer. setDisplay (holder );
②. Solution: Set the callback function for the SurfaceHolder object:
Surfaceview>
// Set the callback method of SurfaceHolder;
Sv. getHolder (). addCallback (new Callback (){
// Call this method when SurfaceHolder is destroyed:
>
Mediaplater. reset (); // return to the Idle status
2. Use setDataSource (); To set the playback data source
3. The underlying c code initializes the player.
Method 1: mediaplayer. prepare ();
Synchronization method.
If no preparation is complete, the following code will not be executed
Mediaplayer. start ();
Method 2: mediaplayer. prepareAsync ();
Asynchronous Method,
To know when to register the onPreparedListener listener after preparation, the internal onPrepared () method is called:
Play the video in the onPrepared () method.
5. Play online video files:
1. If we want to play a Streaming Media Resource online:
The requirement must be a resource file that supports progressive download, that is, the video is divided into several frames of resources, each frame is a picture that can be independently played.
2. resources that support progressive download:
3gp supports http: // protocol download
Rtsp: //>