From the moment the MediaPlayer instance is created to the moment it is terminated, this instance transitions from one state to the next.
Here are the possible states:
IDLE: MediaPlayerStatus.IDLE
INITIALIZING: MediaPlayerStatus.INITIALIZING
INITIALIZED: MediaPlayerStatus.INITIALIZED
PREPARING: MediaPlayerStatus.PREPARING
PREPARED: MediaPlayerStatus.PREPARED
PLAYING: MediaPlayerStatus.PLAYING
PAUSED: MediaPlayerStatus.PAUSED
SEEKING: MediaPlayerStatus.SEEKING
COMPLETE: MediaPlayerStatus.COMPLETE
ERROR: MediaPlayerStatus.ERROR
RELEASED: MediaPlayerStatus.RELEASED
The complete list of states is defined in MediaPlayerStatus
.
Knowing the player’s state is useful because some operations are permitted only while the player is in a particular state. For example, play
cannot be called while in the IDLE state. It must be called after reaching the PREPARED state. The ERROR state also changes what can happen next.
As a media resource is loaded and played, the player transitions in the following way:
The initial state is IDLE.
Your application calls MediaPlayer.replaceCurrentResource
, which moves the player to the INITIALIZING state.
If Browser TVSDK successfully loads the resource, the state changes to INITIALIZED.
Your application calls MediaPlayer.prepareToPlay
, and the state changes to PREPARING.
Browser TVSDK prepares the media stream and starts the ad resolving and ad insertion (if enabled).
When this step is complete, ads are inserted in the timeline or the ad procedure has failed, and the player state changes to PREPARED.
As your application plays and pauses the media, the state moves between PLAYING and PAUSED.
While playing or paused, when you navigate away from the playback, shut down the device, or switch applications, the state changes to SUSPENDED and resources are released. To continue, restore the media player.
When the player reaches the end of the stream, the state becomes COMPLETE.
When your application releases the media player, the state changes to RELEASED.
If an error occurs during the process, the state changes to ERROR.
Here is an illustration of the life cycle of a MediaPlayer instance:
You can use the state to provide feedback to the user on the process (for example, a spinner while waiting for the next state change) or to take the next steps in playing the media, such as waiting for the appropriate state before calling the next method.
For example:
function onStateChanged(state) {
switch(state) {
// It is recommended that you call prepareToPlay()
// after receiving the INITIALIZED state
case AdobePSDK.MediaPlayerStatus.INITIALIZED:
mediaPlayer.prepareToPlay();
break;
}
}