The interface layout is basically the same as the mp3 in the previous section , which requires a control to play the video Surfaceview
The Surfaceview control internally maintains a double-buffered technique that uses two threads to parse frames and display them to the interface
Inside the Activity 's onCreate () method, locate the control object
The other code is consistent with the audio playback in the previous section
Locate the MediaPlayer object that called the setdatasource () method before
Call the Setdisplay () method of the MediaPlayer object to set the movie to play in surfaceholder Way, Parameters: surfaceholder object, call the Getholder () method of the surfaceview object to get
Invokes the Prepareasync () method of the MediaPlayer object for asynchronous preparation
Call the Setonpreparedlistener () method of the MediaPlayer object , set the listener to be completed, and in the overridden method, call the the start () method of the MediaPlayer object
On the lower version of the phone, add the following code to specify that you do not maintain the buffer, waiting for MediaPlayer to push the data out
Call the Getholder () of the Surfaceview object . SetType (surfaceholder.surface_type_push_buffers)
When the interface is minimized, re-opening the Surfaceholder will be destroyed, which is the system design in order to save memory
When the interface is not visible, it should record the playback position and stop, when re-visible, re-open
Gets the Surfaceholder object that invokes the getholder () method of the surfaceview Object
Call the Addcallback () method of the surfaceholder Object , add the callback, parameter:Callback interface type, Use the anonymous inner class to implement the interface, overriding the following methods
Surfacedestroyed (), at the time of destruction
Judge MediaPlayer is not empty and mediaplayer.isplaying () is true
Keep the progress in the Activity 's member variable currentposition , calling the MediaPlayer object's getPosition ()
Stop playing
Surfacecreated (), at the time of Creation
Call the play code, pass the currentposition through the pass , in the ready to complete callback in the back of play , call MediaPlayer The seekto () of the object sets the position last position
Seems to be because there is no support for many formats, the code has not been tested successfully, do not post
[Android] Surfaceview life cycle