public interface

Player

implements Releasable
com.amazonaws.ivs.player.Player

Class Overview

Interface defining a Player. API users instantiate a Player instance via create(Context) and issue api calls to it. The player communicates its state and events back to the user via the Player.Listener interface. The two primary callbacks are for Player.State changes via onStateChanged(Player.State) and for errors onError(PlayerException).

Summary

Nested Classes
class Player.Factory Static class used to instantiate Player instances. 
class Player.Listener Player listener interface. 
enum Player.LogLevel Possible log level values that can be set on a player. 
enum Player.State Represents the current state of a player instance. 
Public Methods
abstract void addListener(Player.Listener listener)
Adds a playback listener that receives information about this player instance.
abstract int getAudioSessionId()
abstract long getAverageBitrate()
abstract long getBandwidthEstimate()
abstract long getBufferedPosition()
abstract long getDuration()
abstract long getLiveLatency()
abstract float getPlaybackRate()
Gets the playback rate for the player.
abstract long getPosition()
abstract Set<Quality> getQualities()
abstract Quality getQuality()
abstract String getSessionId()
abstract Player.State getState()
abstract Statistics getStatistics()
abstract String getVersion()
abstract boolean isAutoQualityMode()
abstract boolean isLiveLowLatency()
abstract boolean isMuted()
abstract void load(Uri uri, String mediaType)
Loads the specified stream.
abstract void load(Uri uri)
Loads the specified stream.
abstract void pause()
Pauses playback of the stream.
abstract void play()
Starts or resumes playback of the stream.
abstract void release()
Releases the player instance.
abstract void removeListener(Player.Listener listener)
Removes a playback state listener.
abstract void seekTo(long position)
Seeks to a specified position in the stream, in milliseconds.
abstract void setAutoInitialBitrate(int bitrate)
Sets the initial starting bitrate when using auto quality mode.
abstract void setAutoMaxBitrate(int bitrate)
Sets the max bitrate when using auto quality mode.
abstract void setAutoMaxQuality(Quality quality)
Sets the max quality when using auto quality mode.
abstract void setAutoMaxVideoSize(int width, int height)
Sets the max video display size of the player.
abstract void setAutoQualityMode(boolean enable)
Enables automatic quality selection (ABR Adaptive bitrate).
abstract void setLiveLowLatencyEnabled(boolean enabled)
Enables low-latency playback for streams which support it.
abstract void setLogLevel(Player.LogLevel level)
Sets the log level for the player, defaults to ERROR.
abstract void setLooping(boolean loop)
Enables the player to loop the source video, for streams that support looping.
abstract void setMuted(boolean muted)
Mutes or unmutes the player audio.
abstract void setPlaybackRate(float rate)
Sets the playback rate for the player.
abstract void setQuality(Quality quality, boolean adaptive)
Sets the quality of the stream.
abstract void setQuality(Quality quality)
Sets the quality of the stream.
abstract void setSurface(Surface surface)
Sets the Surface to use for rendering video.
abstract void setVolume(float volume)
Sets the output gain value for the audio track.
[Expand]
Inherited Methods
From interface com.amazonaws.ivs.player.Releasable

Public Methods

public abstract void addListener (Player.Listener listener)

Adds a playback listener that receives information about this player instance.

Parameters
listener to add

public abstract int getAudioSessionId ()

Returns
  • Audio session ID of the audio track. This method returns a valid value only after a stream is loaded and in the playing state (PLAYING.

public abstract long getAverageBitrate ()

Returns
  • Average source media bitrate of the stream in bps.

public abstract long getBandwidthEstimate ()

Returns
  • For network streams, the ABR bandwidth estimate in bps or 0 if unknown.

public abstract long getBufferedPosition ()

Returns
  • The playback position in milliseconds or -1 if no data is buffered.

public abstract long getDuration ()

Returns
  • The duration of the loaded stream in milliseconds. This returns -1 if no stream is loaded or the stream length is infinite or unknown.

public abstract long getLiveLatency ()

Returns
  • For a live stream, the latency to the source in milliseconds.

public abstract float getPlaybackRate ()

Gets the playback rate for the player.

public abstract long getPosition ()

Returns
  • The playback position in milliseconds, if the player is in the PLAYING state. Otherwise, this returns the last play position or -1 if not started yet.

public abstract Set<Quality> getQualities ()

Returns
  • Set of Quality objects available for the stream. This method returns an empty set until the player enters the READY state.

public abstract Quality getQuality ()

Returns

public abstract String getSessionId ()

Returns
  • A unique identifier for the playback session. The session identifier can be shared with support or displayed in a user interface, to help troubleshoot or diagnose playback issues with the stream.

public abstract Player.State getState ()

Returns

public abstract Statistics getStatistics ()

Returns

public abstract String getVersion ()

Returns
  • The version of the player.

public abstract boolean isAutoQualityMode ()

Returns
  • true if auto quality switching is enabled, false otherwise.

public abstract boolean isLiveLowLatency ()

Returns
  • true if the player is in low-latency mode, false otherwise.

public abstract boolean isMuted ()

Returns
  • true if the player is muted, false otherwise

public abstract void load (Uri uri, String mediaType)

Loads the specified stream. On success, the player state changes to READY. On failure, this invokes onError(PlayerException).

Parameters
uri of the stream to load (e.g. a url or file)
mediaType Media type of the content if known, e.g. "video/mp4" or "application/x-mpegURL"

public abstract void load (Uri uri)

Loads the specified stream. On success, the player state changes to READY. On failure, this invokes onError(PlayerException).

Parameters
uri of the stream to load (e.g. a url or file)

public abstract void pause ()

Pauses playback of the stream. This fails if no stream is loaded. On failure, this invokes onError(PlayerException).

Resuming the stream with play may result in the position being different depending on the type of source being played.

public abstract void play ()

Starts or resumes playback of the stream. This fails if no stream is loaded. On success, depending on the type of stream, the player state changes to BUFFERING and then PLAYING, or just PLAYING. On failure, this invokes the onError callback.

public abstract void release ()

Releases the player instance. This method must be called when the Player is no longer being used, to free network and system resources. The player cannot be used after this method is called.

public abstract void removeListener (Player.Listener listener)

Removes a playback state listener.

Parameters
listener to remove

public abstract void seekTo (long position)

Seeks to a specified position in the stream, in milliseconds. Seeks to the given time in the stream and begins playing at that position if play() has been called. On success, depending on the type of stream the player state will change to BUFFERING and then PLAYING or remain in PLAYING. getPosition() will update to the seeked time. On failure, invokes the onError listener method.

Parameters
position to seek to in milliseconds

public abstract void setAutoInitialBitrate (int bitrate)

Sets the initial starting bitrate when using auto quality mode. This determines the initial quality for an adaptive stream, when no bandwidth estimate value has been determined.

Parameters
bitrate initial bitrate to use

public abstract void setAutoMaxBitrate (int bitrate)

Sets the max bitrate when using auto quality mode. Allows you to control resource usage in the case of multiple players.

Parameters
bitrate bitrate to use

public abstract void setAutoMaxQuality (Quality quality)

Sets the max quality when using auto quality mode. Allows you to control resource usage. The Quality you provide here is applied to the current stream. If you load a new stream, call this again after READY.

Parameters
quality maximum quality to use

public abstract void setAutoMaxVideoSize (int width, int height)

Sets the max video display size of the player. This prevents switching to qualities above the specified resolution when autoSwitchQuality is true.

Parameters
width display width
height display height

public abstract void setAutoQualityMode (boolean enable)

Enables automatic quality selection (ABR Adaptive bitrate). The player will choose the quality to play based on the current network and device conditions. The player by default starts in this mode. This mode is implicitly disabled by a call to setQuality(Quality).

Parameters
enable true to enable auto quality selection, false to disable.

public abstract void setLiveLowLatencyEnabled (boolean enabled)

Enables low-latency playback for streams which support it. Defaults to true. Changing this value during playback restarts the stream.

Parameters
enabled true to enable, false to disable

public abstract void setLogLevel (Player.LogLevel level)

Sets the log level for the player, defaults to ERROR.

Parameters
level to set

public abstract void setLooping (boolean loop)

Enables the player to loop the source video, for streams that support looping.

Parameters
loop true to loop video playback, false otherwise

public abstract void setMuted (boolean muted)

Mutes or unmutes the player audio.

Parameters
muted true to mute the player false to unmute the player

public abstract void setPlaybackRate (float rate)

Sets the playback rate for the player.

Parameters
rate rate to set

public abstract void setQuality (Quality quality, boolean adaptive)

Sets the quality of the stream. If auto quality mode is enabled, calling this method disables it.

Parameters
quality to set
adaptive true for an adaptive quality change (quality changes at the end of the buffer, false otherwise buffer cleared immediately)

public abstract void setQuality (Quality quality)

Sets the quality of the stream. If auto quality mode is enabled, calling this method disables it.

Parameters
quality to set

public abstract void setSurface (Surface surface)

Sets the Surface to use for rendering video. This method can be called at any time. A valid surface must be set, to play video. When using a android.view.SurfaceView or android.view.TextureView, the application must listen for the corresponding lifecycle callbacks, for SurfaceView surfaceCreated(SurfaceHolder) and surfaceDestroyed(SurfaceHolder) for TextureView onSurfaceTextureAvailable(SurfaceTexture, int, int) and onSurfaceTextureDestroyed(SurfaceTexture) )} in order to set the surface on the player and clear it, by setting it to null, when the surface is being destroyed.

Parameters
surface surface to use for rendering. this value can be null to stop displaying video

public abstract void setVolume (float volume)

Sets the output gain value for the audio track.

Parameters
volume volume for the audio track between 0.0f and 1.0f