Mediaplayer Lifecycle
<1> Android mediaplayer provides the audio and video playback functions. On the android interface, the app music and video are used.ProgramAll are implemented by calling mediaplayer.
Mediaplayer is implemented at the underlying layer based on the opencore (packetvideo) Library. To build a mediaplayer program, the upper layer also contains inter-process communication and other content, the basis for inter-process communication is the Binder Mechanism in the basic Android library.
<2> when a mediaplayer object is created or the reset () method is called, it is in idle state and the release () method is called.
<3> when a mediaplayer object is no longer used, it is best to use the release () method to release it to an end state to avoid unnecessary errors.
When the mediaplayer object is in the end state, it cannot be used.
<3> when a mediaplayer object is in idle state after it is created, it is in preparation state if it is created using the CREATE () method.
<4> Any mediaplayer object must be in preparation before playing.
<5> to start playing a mediaplayer object, you must call the START () method successfully. You can use the isplaying () method to determine whether the video is being played.
<6> when a mediaplayer object is being played, you can pause or stop it. Pause () is used to pause the video and stop () is used to stop the video.
The START () method can be used to resume playing when the player is in the paused state. However, you must call the pause () method to make the player in the prepared state, and then start () method to start playing.
<7> you can use the setlooping (Boolean) method to set whether to play cyclically.
Common mediaplayer Methods
Playing music on Android is easy:
Mediaplayer media = new mediaplayer (); // constructs the object media. setdatasource ("/sdcard/boys.mp3"); // sets the file path media. prepare (); // prepare media. start (); // start playing