Triton Mobile SDK for Android
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
com.tritondigital.player.MediaPlayer Class Referenceabstract

Base class for a media player. More...

Inheritance diagram for com.tritondigital.player.MediaPlayer:
com.tritondigital.player.SbmPlayer com.tritondigital.player.TritonPlayer

Classes

interface  OnAnalyticsReceivedListener
 Callback for receiving analytics event. More...
 
interface  OnCloudStreamInfoReceivedListener
 Callback for receiving timeshift programs event. More...
 
interface  OnCuePointReceivedListener
 Callback for receiving CuePoint. More...
 
interface  OnInfoListener
 Callback for receiving player info. More...
 
interface  OnMetaDataReceivedListener
 Callback for receiving Metadata. More...
 
interface  OnStateChangedListener
 Callback for receiving state changes. More...
 

Public Member Functions

 MediaPlayer (Context context, Bundle settings)
 Constructor. More...
 
abstract int getDuration ()
 Returns the duration of the current media in milliseconds. More...
 
int getErrorCode ()
 
Bundle getLastCuePoint ()
 Returns the last received cue point.
 
int getLastErrorCode ()
 Returns the last error code.
 
OnMetaDataReceivedListener getMetadataListener ()
 Returns the metadata listener.
 
OnCuePointReceivedListener getOnCuePointReceivedListener ()
 Returns the cue point listener.
 
OnInfoListener getOnInfoListener ()
 Returns the info listener.
 
OnStateChangedListener getOnStateChangedListener ()
 Returns the state changed listener.
 
abstract int getPosition ()
 Returns the current position playback position in milliseconds.
 
Bundle getSettings ()
 Returns the settings of this player.
 
int getState ()
 Returns the player's state.
 
abstract float getVolume ()
 Returns the current volume (0.0f to 1.0f)
 
boolean isPausable ()
 Returns true if the media can be paused at the current state.
 
boolean isSeekable ()
 Returns true if the media is seekable in the current state. More...
 
abstract boolean isTimeshiftStreaming ()
 Returns if the player is in timeshift mode.
 
final void pause ()
 Pauses the playback so it can be resumed at the same position by calling play(). More...
 
final void play (boolean timeshiftStreaming)
 Starts the playback.
 
final void release ()
 Releases the player resources. More...
 
void seek (int delta)
 Seek to a time from the current position.
 
final void seekTo (int position)
 Seek to the provided position. More...
 
final void seekTo (int position, int original)
 Seek to the provided position. More...
 
void setOnAnalyticsReceivedListener (OnAnalyticsReceivedListener listener)
 Sets the analytics changed listener.
 
void setOnCloudStreamInfoReceivedListener (OnCloudStreamInfoReceivedListener listener)
 Sets the timeshift programs listener.
 
void setOnCuePointReceivedListener (OnCuePointReceivedListener listener)
 Sets the cue point event listener.
 
void setOnInfoListener (OnInfoListener listener)
 Sets the info listener.
 
void setOnMetaDataReceivedListener (OnMetaDataReceivedListener listener)
 Sets the cue point event listener.
 
void setOnStateChangedListener (OnStateChangedListener listener)
 Sets the state changed listener.
 
abstract void setVolume (float volume)
 Sets the volume on this player. More...
 
final void stop ()
 Stops the playback.
 

Static Public Member Functions

static String debugErrorToStr (int errorCode)
 Utility method to convert an error code to a debug string. More...
 
static String debugInfoToStr (int info)
 Utility method to convert an info code to a debug string. More...
 
static String debugStateToStr (int state)
 Utility method to convert the player state to a debug string. More...
 
static boolean isPlayValidInState (int state)
 Returns true if a play request is valid in the provided state.
 
static boolean isTransitionValid (int state0, int state1)
 Returns true if the provided state transition is valid. More...
 

Static Public Attributes

static final int DURATION_LIVE_STREAM = Integer.MAX_VALUE
 Live stream.
 
static final int DURATION_UNKNOWN = -1
 Unknown duration.
 
static final int ERROR_CONNECTION_FAILED = 211
 Error code indicating a connection problem to the server.
 
static final int ERROR_CONNECTION_TIMEOUT = 408
 Error code indicating than the connection has timed out.
 
static final int ERROR_END_OF_MEDIA = ERROR_UNEXPECTED_END_OF_MEDIA
 
static final int ERROR_EXOPLAYER_BUFFER_RECONNECT = 212
 Error code indicating that low delay increased 3 times an still did not fill the buffer.
 
static final int ERROR_EXOPLAYER_BUFFER_TIMEOUT = 218
 Error code indicating buffer timed out. More...
 
static final int ERROR_EXOPLAYER_ON_ERROR = 219
 Error code indicating buffer timed out. More...
 
static final int ERROR_GEOBLOCKED = 453
 Error code indicating that the stream can't be used in the user location.
 
static final int ERROR_INVALID_URL = 216
 Error code indicating that the URL isn't in a valid format.
 
static final int ERROR_LOW_LEVEL_PLAYER_ERROR = 210
 Error code indicating an error in the OS player or Google Cast.
 
static final int ERROR_NO_NETWORK = 217
 Error code indicating the lack of network connectivity.
 
static final int ERROR_NOT_FOUND = 404
 Error code indicating that the input source couldn't be found.
 
static final int ERROR_SERVICE_UNAVAILABLE = 503
 Error code indicating that no server is available.
 
static final int ERROR_UNEXPECTED_END_OF_MEDIA = 213
 Error code indicating the end of a media which shouldn't occur on live streaming.
 
static final int ERROR_UNEXPECTED_END_OF_MEDIA_ANDROID_PLAYER = 214
 Error code indicating the end of a media which shouldn't occur on live streaming.
 
static final int INFO_ALTERNATE_MOUNT = 270
 A the player has connected to an alternate mount.
 
static final int INFO_BUFFERING_COMPLETED = 276
 The playback is resumed after filling buffers.
 
static final int INFO_BUFFERING_START = 275
 Temporarily pausing playback internally in order to buffer more data.
 
static final int INFO_DURATION_CHANGED = 272
 Media duration changed (extra=duration)
 
static final int INFO_SEEK_COMPLETED = 271
 A seek operation has completed.
 
static final int INFO_SEEK_STARTED = 274
 A seek operation has begun.
 
static final int INFO_SEEKABLE_CHANGED = 273
 Seekable state change (0=false / 1=true)
 
static final int POSITION_UNKNOWN = 0
 Unknown position.
 
static final int STATE_COMPLETED = 200
 The end of the media source has been reached (on-demand only)
 
static final int STATE_CONNECTING = 201
 The player is connecting to the server or buffering.
 
static final int STATE_ERROR = 202
 An error has occurred.
 
static final int STATE_PAUSED = 206
 The playback is paused (on-demand only)
 
static final int STATE_PLAYING = 203
 The playback is started.
 
static final int STATE_RELEASED = 204
 The resources have been released and this player instance can no longer be used.
 
static final int STATE_STOPPED = 205
 The playback is stopped.
 
static final float VOLUME_DUCK = 0.2f
 Ducked volume.
 
static final float VOLUME_MUTE = 0.0f
 Muted volume.
 
static final float VOLUME_NORMAL = 1.0f
 Normal volume.
 

Detailed Description

Base class for a media player.

Always use the constants instead of hardcoding the values in your app.

Life Cycle

Constructor & Destructor Documentation

◆ MediaPlayer()

com.tritondigital.player.MediaPlayer.MediaPlayer ( Context  context,
Bundle  settings 
)

Constructor.

A copy "settings" is made to make sure the client doesn't modified it while the MediaPlayer is using it.

Exceptions
IllegalArgumentExceptionif context is null
IllegalArgumentExceptionif settings is null

Member Function Documentation

◆ debugErrorToStr()

static String com.tritondigital.player.MediaPlayer.debugErrorToStr ( int  errorCode)
static

Utility method to convert an error code to a debug string.

Note
To be used only for debugging purpose.

◆ debugInfoToStr()

static String com.tritondigital.player.MediaPlayer.debugInfoToStr ( int  info)
static

Utility method to convert an info code to a debug string.

Note
To be used only for debugging purpose.

◆ debugStateToStr()

static String com.tritondigital.player.MediaPlayer.debugStateToStr ( int  state)
static

Utility method to convert the player state to a debug string.

Note
To be used only for debugging purpose.

◆ getDuration()

abstract int com.tritondigital.player.MediaPlayer.getDuration ( )
abstract

Returns the duration of the current media in milliseconds.

Return values
MediaPlayer.DURATION_LIVE_STREAMLive stream
MediaPlayer.DURATION_UNKNOWNUnavailable duration

◆ getErrorCode()

int com.tritondigital.player.MediaPlayer.getErrorCode ( )
Deprecated
Use MediaPlayer::getLastErrorCode() instead

◆ isSeekable()

boolean com.tritondigital.player.MediaPlayer.isSeekable ( )

Returns true if the media is seekable in the current state.

For now, it is the same as MediaPlayer.isPausable()

◆ isTransitionValid()

static boolean com.tritondigital.player.MediaPlayer.isTransitionValid ( int  state0,
int  state1 
)
static

Returns true if the provided state transition is valid.

Parameters
state0Initial state.
state1Final state.

◆ pause()

final void com.tritondigital.player.MediaPlayer.pause ( )

Pauses the playback so it can be resumed at the same position by calling play().

For live content, this method does the same as MediaPlayer.stop().

◆ release()

final void com.tritondigital.player.MediaPlayer.release ( )

Releases the player resources.

No other method may be called on this instance after release.

◆ seekTo() [1/2]

final void com.tritondigital.player.MediaPlayer.seekTo ( int  position)

Seek to the provided position.

Does nothing if the media isn't loaded or seekable.

◆ seekTo() [2/2]

final void com.tritondigital.player.MediaPlayer.seekTo ( int  position,
int  original 
)

Seek to the provided position.

Does nothing if the media isn't loaded or seekable.

◆ setVolume()

abstract void com.tritondigital.player.MediaPlayer.setVolume ( float  volume)
abstract

Sets the volume on this player.

This method can be used to lower the volume when losing the device audio focus. http://developer.android.com/training/managing-audio/audio-focus.html

Parameters
volumeVolume (0.0f to 1.0f)

Member Data Documentation

◆ ERROR_END_OF_MEDIA

final int com.tritondigital.player.MediaPlayer.ERROR_END_OF_MEDIA = ERROR_UNEXPECTED_END_OF_MEDIA
static

◆ ERROR_EXOPLAYER_BUFFER_TIMEOUT

final int com.tritondigital.player.MediaPlayer.ERROR_EXOPLAYER_BUFFER_TIMEOUT = 218
static

Error code indicating buffer timed out.

Increase the lowdelay value

◆ ERROR_EXOPLAYER_ON_ERROR

final int com.tritondigital.player.MediaPlayer.ERROR_EXOPLAYER_ON_ERROR = 219
static

Error code indicating buffer timed out.

Increase the lowdelay value