public final class BroadcastPlayer extends Object implements MediaController.MediaPlayerControl
KITKAT
, Android 4.4.
BroadcastPlayer implements the MediaController.MediaPlayerControl
interface and can thereby be passed to a standard MediaController
widget for
pause/resume/seek in an archived broadcast. Pause/resume/seek is disabled during normal
low-latency playback of a live broadcast, but can be enabled by switching to high-latency
timeshift mode through setTimeshiftMode(true)
.
The onBroadcastLoaded(live, width, height)
callback is suitable for showing relevant UI components.
Modifier and Type | Class and Description |
---|---|
static class |
BroadcastPlayer.AcceptType |
static class |
BroadcastPlayer.LatencyMode |
static interface |
BroadcastPlayer.Observer |
static interface |
BroadcastPlayer.ViewerCountObserver
An interface that should be passed to
setViewerCountObserver(ViewerCountObserver) to receive callbacks about the
current and total number of viewers of the broadcast. |
Constructor and Description |
---|
BroadcastPlayer(Context context,
String resourceUri,
String applicationId,
BroadcastPlayer.Observer observer)
Creates a BroadcastPlayer instance in the
PlayerState.CONSTRUCTION state. |
Modifier and Type | Method and Description |
---|---|
boolean |
canPause()
Implementation for the
MediaController.MediaPlayerControl interface,
determining whether the broadcast can be paused/resumed. |
boolean |
canSeekBackward()
Implementation for the
MediaController.MediaPlayerControl interface,
determining whether the BroadcastPlayer currently supports seeking. |
boolean |
canSeekForward()
Implementation for the
MediaController.MediaPlayerControl interface,
determining whether the BroadcastPlayer currently supports seeking. |
void |
close()
Immediately stops any playback and frees all related system resources.
|
int |
getAudioSessionId()
Returns the current audio session id if a broadcast has been loaded.
|
String |
getBroadcastId()
Returns the id of the loaded broadcast.
|
int |
getBufferPercentage()
Implementation for the
MediaController.MediaPlayerControl interface,
returning a current buffer percentage for an archived broadcast. |
int |
getCurrentPosition()
Get the current play position in a video.
|
int |
getDuration()
Get the duration of the currently playing video.
|
LatencyMeasurement |
getEndToEndLatency()
Get the current measured end-to-end latency when playing a live broadcast.
|
PlayerState |
getState()
Get the current state
|
boolean |
isPlaying()
Implementation for the
MediaController.MediaPlayerControl interface,
determining whether the MediaController should show a pause or play button. |
boolean |
isTypeLive()
Returns the type of the broadcast.
|
void |
load()
Starts loading the requested Bambuser broadcast for playback.
|
void |
pause()
|
void |
seekTo(int position)
Seek to desired position.
|
void |
setAcceptType(BroadcastPlayer.AcceptType acceptedBroadcastType)
Set the type accepted when loading the broadcast.
|
void |
setAudioVolume(float volume)
Set the desired audio volume for this BroadcastPlayer instance.
|
void |
setLatencyMode(BroadcastPlayer.LatencyMode mode)
Set whether the player should prioritize low latency or playback with less interruptions.
|
void |
setSurface(Surface surface)
Set the Surface where video should be shown.
|
void |
setSurfaceView(SurfaceView surfaceView)
Set the SurfaceView where video will be shown.
|
void |
setTextureView(TextureView textureView)
Set the TextureView where video will be shown.
|
void |
setTimeshiftMode(boolean enabled)
Set whether the player should be configured for timeshift mode.
|
void |
setViewerCountObserver(BroadcastPlayer.ViewerCountObserver observer)
Get the number of viewers into your app by implementing a
BroadcastPlayer.ViewerCountObserver . |
void |
start()
|
public BroadcastPlayer(Context context, String resourceUri, String applicationId, BroadcastPlayer.Observer observer)
PlayerState.CONSTRUCTION
state. After this,
you should use setSurfaceView(SurfaceView)
, setTextureView(TextureView)
or setSurface(Surface)
. Then
you may set optional features, such as setAcceptType(AcceptType)
and
setAudioVolume(float)
, and call load()
.
Always call close()
when the instance is no longer needed, to stop playback and
free allocated resources.
context
- Context providing system information needed for playback.resourceUri
- A signed resource URI for a Bambuser broadcast, for example received from the Bambuser Metadata API.applicationId
- Customer app specific secret ID, ensuring access to the customer's content.observer
- Implement the BroadcastPlayer.Observer
interface to receive callbacks about state
changes in the BroadcastPlayer.public void setAcceptType(BroadcastPlayer.AcceptType acceptedBroadcastType)
load()
.acceptedBroadcastType
- Use BroadcastPlayer.AcceptType.LIVE
or BroadcastPlayer.AcceptType.ARCHIVED
to
allow playback of only the specified broadcast type. The default is BroadcastPlayer.AcceptType.ANY
.public void setTimeshiftMode(boolean enabled)
load()
.enabled
- True to configure the player for timeshift mode, false otherwise.public void setLatencyMode(BroadcastPlayer.LatencyMode mode)
LOW
latency mode, the player prioritizes low latency and is quick
to start initial playback.
In HIGH
latency mode, the player uses larger buffers and will buffer
slightly more initially, to minimize the risk of playback interruptions due to network
fluctuations.
This option currently only affects live broadcasts.
This method can only be used before the first call to load()
.
mode
- A BroadcastPlayer.LatencyMode
. Default is BroadcastPlayer.LatencyMode.LOW
.public void setSurfaceView(SurfaceView surfaceView)
SurfaceView
is
a SurfaceViewWithAutoAR
and is allowed to set its own dimensions, the BroadcastPlayer will
automatically set its aspect ratio.surfaceView
- A SurfaceView (preferably a SurfaceViewWithAutoAR
) where the video
will be shown.public void setTextureView(TextureView textureView)
TextureView
is provided, the
BroadcastPlayer will attempt to keep the screen on while video is playing.
The BroadcastPlayer will use TextureView.setSurfaceTextureListener(TextureView.SurfaceTextureListener)
,
overriding any existing listener.textureView
- A TextureView where the video will be shown.public void setSurface(Surface surface)
setSurfaceView(SurfaceView)
or
setTextureView(TextureView)
are better.surface
- Surface where the video will be shown.public void load()
PlayerState.CONSTRUCTION
state.public void close()
public boolean isTypeLive()
LOADING
to
BUFFERING
/PLAYING
).
The value is not updated later.public String getBroadcastId()
LOADING
to
BUFFERING
/PLAYING
).
For example when a player is initiated with a virtual resource uri, this method can be used to determine which broadcast the player loaded.
public PlayerState getState()
PlayerState
.public int getDuration()
getDuration
in interface MediaController.MediaPlayerControl
public int getCurrentPosition()
getCurrentPosition
in interface MediaController.MediaPlayerControl
public void seekTo(int position)
seekTo
in interface MediaController.MediaPlayerControl
position
- Desired playback position in milliseconds.public LatencyMeasurement getEndToEndLatency()
Broadcaster
and BroadcastPlayer
can synchronize
their clocks with the servers and the player can determine the current end-to-end latency.
End-to-end latency measurements may take a while before appearing and may not be available for all broadcasts, as it requires successful clock synchronization and needs to be supported by the broadcast source too.
LatencyMeasurement
object containing the current end-to-end latency and
the total uncertainty of the broadcaster and player.
null if end-to-end latency measurement is currently unavailable.public boolean isPlaying()
MediaController.MediaPlayerControl
interface,
determining whether the MediaController
should show a pause or play button.isPlaying
in interface MediaController.MediaPlayerControl
PLAYING
or
BUFFERING
, false otherwise.public int getBufferPercentage()
MediaController.MediaPlayerControl
interface,
returning a current buffer percentage for an archived broadcast.getBufferPercentage
in interface MediaController.MediaPlayerControl
public boolean canPause()
MediaController.MediaPlayerControl
interface,
determining whether the broadcast can be paused/resumed.canPause
in interface MediaController.MediaPlayerControl
public boolean canSeekBackward()
MediaController.MediaPlayerControl
interface,
determining whether the BroadcastPlayer currently supports seeking.canSeekBackward
in interface MediaController.MediaPlayerControl
public boolean canSeekForward()
MediaController.MediaPlayerControl
interface,
determining whether the BroadcastPlayer currently supports seeking.canSeekForward
in interface MediaController.MediaPlayerControl
public int getAudioSessionId()
getAudioSessionId
in interface MediaController.MediaPlayerControl
public void setViewerCountObserver(BroadcastPlayer.ViewerCountObserver observer)
BroadcastPlayer.ViewerCountObserver
.observer
- An observer object enabling viewer count functionality.public void setAudioVolume(float volume)
This method can be used at any time, and is suitable for silencing individual player instances, as it does not affect the global audio stream volume.
volume
- float value between 0.0 and 1.0. The default is 1.0.public void pause()
pause
in interface MediaController.MediaPlayerControl
public void start()
PAUSED
broadcast, or restart playback
of a COMPLETED
archived broadcast.
This method is only applicable when an archived broadcast (or a live broadcast in timeshift
mode) has been loaded.start
in interface MediaController.MediaPlayerControl