From the moment that you create the MediaPlayer instance to the moment when you terminate (reuse or remove) it, this instance completes a series of transitions between statuses.
Some operations are permitted only when the player is in a particular state. For example, calling play
in IDLE is not allowed. You can call this status only after the player reaches the PREPARED state.
To work with statuses:
You can retrieve the current state of the MediaPlayer
object by using the MediaPlayer.status
property.
function get status():String;
The list of statuses is defined in MediaPlayer.PlayerStatus
.
State-transition diagram for the lifecycle of a MediaPlayer
instance:
The following table provides additional details:
MediaPlayerStatus | Occurs when |
---|---|
IDLE | Your application requested a new media player by instantiating MediaPlayer . The newly created player is waiting for you to specify a media player item. |
INITIALIZING | Your application called MediaPlayer.replaceCurrentResource , and the media player is loading. |
INITIALIZED | TVSDK successfully set the media player item. |
PREPARING | Your application called MediaPlayer.prepareToPlay . The media player is loading the media player item and the associated resources. Tip: Some buffering of the main media might occur. TVSDK is preparing the media stream and attempting to perform ad resolving and ad insertion, (if enabled). Tip: To set the start time to a non-zero value, call prepareToPlay(startTime) with the time in milleseconds. |
PREPARED | The content is prepared and ads have been inserted in the timeline, or the ad procedure failed. Buffering or playback can begin. |
PLAYING | Your application has called play , so TVSDK is trying to play the video. Some buffering might occur before the video actually plays. |
PAUSED | As your application plays and pauses the media, the media player moves between this state and PLAYING. |
SEEKING | The media player is seeking to the correct position while paused or playing. To determine when seeking has started or ended, listen for the SeekEvent.SEEK_BEGIN and SeekEvent.SEEK_END events. |
COMPLETED | The player reached the end of the stream, and playback has stopped. |
RELEASED | Your application has released the media player, which also releases any associated resources. You can no longer use this instance |
ERROR | An error occurred during the process. An error also might affect what your application can do next. |
You can use the status to provide feedback on the process (for example, a spinner while waiting for the next status change) or to take the next step in playing the media, such as waiting for the appropriate status before calling the next method.