From the moment when the PTMediaPlayer instance is created to the moment it is terminated (reused or removed), the PTMediaPlayer object completes a series of transitions from one status to another.
The list of statuses is defined in PTMediaPlayerStatus. You can retrieve the current of the PTMediaPlayer object with PTMediaPlayer.status.
Knowing the player’s status is useful because some operations are permitted only while the player is in a particular status. For example, play cannot be called while in PTMediaPlayerStatusCreated. It must be called after reaching the PTMediaPlayerStatusReady status.
The PTMediaPlayerStatusError status also changes what can happen next.
Here is how the basic procedure for loading a media resource inside the PTMediaPlayer corresponds to state transitions:
The initial status is PTMediaPlayerStatusCreated.
Your application calls PTMediaPlayer.replaceCurrentItemWithPlayerItem, which moves the player to PTMediaPlayerStatusInitializing.
The PSDK loads the resource. If successful, the status becomes PTMediaPlayerStatusInitialized.
Your application calls PTMediaPlayer.prepareToPlay.
The PSDK prepares the media stream and starts the ad resolving and ad insertion (if enabled).
When this finishes (either ads are inserted into the timeline or the ad procedure has failed), the player status becomes PTMediaPlayerStatusReady.
As your application plays and pauses the media, the status moves between PTMediaPlayerStatusPlaying and PTMediaPlayerStatusPaused.
When the player reaches the end of the stream, the status becomes PTMediaPlayerStatusCompleted.
When your application releases the media player, the status becomes PTMediaPlayerStatusStopped.
If an error occurs at any time during the process, the status becomes PTMediaPlayerStatusError.
You can use the status to provide feedback to the user on the process (for example, a spinner while waiting for the next status change) or to take the next steps in playing the media, such as waiting for the appropriate status before calling the next method.