Class PlayerController
- java.lang.Object
-
- com.castlabs.android.player.PlayerController
-
- Direct Known Subclasses:
SingleControllerPlaylist
public class PlayerController extends Object
This class allows you to control and manage the video player instance and receive feedback during playback. Note that you usually do not need to create instances of the controller manually. Use thePlayerView
implementation and itsPlayerView.getPlayerController()
method to get the controller instance for the current view. You can addPlayerListener
instances to this controller to get informed about state changes of the underlying player. All listener methods are called from within the main thread of your application.- Since:
- 1.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PlayerController.State
Represents states of the player backend.static interface
PlayerController.TrackType
-
Field Summary
Fields Modifier and Type Field Description static int
AUDIO_RENDERER
Identifies the audio trackstatic int
DTS_RENDERER
Identifies the dts audio renderersstatic int
METADATA_RENDERER
Identifies the metadata renderers for HLS ID3 metadatastatic int
TEXT_RENDERER
Identifies the subtitle trackstatic int
UNKNOWN_RENDERER
Identifies an unknown trackstatic int
VIDEO_RENDERER
Identifies the video track
-
Constructor Summary
Constructors Constructor Description PlayerController(Context context)
Create a new player controller using the given context
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAudioRendererListener(AudioRendererListener listener)
Add an audio renderer listenervoid
addCatchupListener(CatchupListener listener)
Add a Catchup listenervoid
addCustomDashEventListener(CustomDashEventListener listener)
Add a new event listener to receive custom DASH eventsvoid
addDrmEventListener(DrmEventListener listener)
Add aDrmEventListener
.void
addFormatChangeListener(FormatChangeListener listener)
Add a new Format change listener.void
addHttpListener(HttpListener listener)
Add a HTTP listenervoid
addMetadataListener(MetadataListener listener)
Add a new event listener to receive updates on ID3 Meta-Data tags from HLS streams.void
addPeriodChangedListener(PeriodChangedListener listener)
Adds a listener to receive updates onTimeline.Period
changesvoid
addPlayerControllerListener(PlayerControllerListener listener)
Add a new player controller listenervoid
addPlayerListener(PlayerListener listener)
Add aPlayerListener
.void
addPlayerModelFilter(PlayerModelFilter filter)
Adds aPlayerModelFilter
.void
addRequestModifier(RequestModifier modifier)
Add a request modifier.void
addResponseModifier(ResponseModifier modifier)
Add a response modifier.void
addStreamingEventListener(StreamingEventListener listener)
Add a new event listener.void
addSubtitleTrack(String url, String mimeType, String language, String name)
Add a subtitles track to be side-loaded when content is opened.void
addThumbnailTrack(ThumbnailDataTrack thumbnailDataTrack)
Adds a thumbnail track.void
addTimelineChangedListener(TimelineChangedListener listener)
Adds a listener to receive updates onTimeline
updatesvoid
addTimelineListener(TimelineListener listener)
Deprecated.void
addTrackSelectionListener(TrackSelectionListener listener)
Add a new event listener to receive updates related to track selection.void
addVideoRendererListener(VideoRendererListener listener)
Add a video renderer listenercom.google.android.exoplayer2.source.MediaSource
createContentMediaSource(PlayerConfig playerConfig, PlayerPlugin playerPlugin)
Creates a MediaSource for just one PlayerConfig.void
destroy()
Call this method when the activity that displays the video player is destroyed.void
disableAudioFocus()
Disables the audio focus for the stream regardless of thePlayerConfig.audioAttributes
void
enableTrickplayMode(boolean enable)
Enables or disables trickplay playback.AbrConfiguration
getAbrConfiguration()
Returns the current ABR configurationAdClientInterface
getAdClientInterface()
Gets access toAdClientInterface
APIsAdInterface
getAdInterface()
Gets access toAdInterface
APIsAnalyticsMetaData
getAnalyticsMetaData()
AnalyticsSession
getAnalyticsSession()
Get the current analytics session if there is one.com.google.android.exoplayer2.audio.AudioAttributes
getAudioAttributes()
com.google.android.exoplayer2.AudioFocusCallback
getAudioFocusCallback()
AudioTrack
getAudioTrack()
Returns the current audio track.List<AudioTrack>
getAudioTracks()
Returns a list of audio track assets found in the opened movie meta data.long
getBackBufferTime()
Returns the oldest position that still has buffered content, in microseconds.BandwidthMeterWrapper
getBandwidthMeterWrapper()
The bandwidth meter wrapperlong
getBitrateEstimate()
Returns the estimated bandwidth in bits/sec.BufferConfiguration
getBufferConfiguration()
Returns the buffer configuration of this controllerint
getBufferedPercentage()
Returns an estimate of the percentage in the current content window or ad up to which data is buffered, or 0 if no estimate is available.long
getBufferedPosition()
Returns an estimate of the position in the current content window or ad up to which data is buffered, in microseconds.int
getBufferSizeBytes()
Return the current buffer size in byteslong
getBufferSizeTime()
Return the current buffer size ahead of the playhead in media time microseconds<T> T
getComponent(Class<T> type)
Returns the player component of the given type if it exists.View
getComponentView(int viewId)
Returns a View previously set throughsetComponentView(int, View)
and indexed with a view id.Context
getContext()
DataSourceFactory
getDataSourceFactory()
Provides access to theDataSourceFactory
.long
getDuration()
Get the duration in microseconds of a region of media currently available for playback (including both live and static streams) or -1 if no duration is available for the current stream.HlsClearKeyCache
getHlsKeyCache()
Returns the currentHlsClearKeyCache
used for HLS Clearkey requests.static KeyStore
getKeyStore()
Returns theKeyStore
that will be used to store offline IDs or null if no store is configured.long
getLicenseRemainingDurationSec()
Returns the remaining license duration for the current DRM session.long
getLicenseRemainingDurationSec(TrackRendererPlugin.Type trackType)
Returns the remaining license duration for the current DRM session.LiveConfiguration
getLiveConfiguration()
Returns the live configuration of this controllerint
getLiveEdgeLatency()
For live streams, the number of milliseconds that the playback should lag behind the "live edge" (i.e.long
getLiveEdgeUs()
Returns the live edge time in microseconds, orC.TIME_UNSET
if unknown or not applicable.long
getLiveEdgeUs(boolean applyOffset)
Returns the live edge time in microseconds, orC.TIME_UNSET
if unknown or not applicable.long
getLiveStartTime()
Get the live start time in microseconds since the epoch or -1 if unknown or not applicable.Handler
getMainHandler()
int
getMaxBufferSizeBytes()
Return the maximum buffer size in bytescom.google.android.exoplayer2.mediacodec.MediaCodecSelector
getMediaCodecSelector()
NetworkConfiguration
getNetworkConfiguration()
String
getOfflinePath()
Gets the local path to the currently played content if it is played offline, otherwisenull
String
getPath()
Returns the path set in this controller or nullcom.google.android.exoplayer2.ExoPlayer
getPlayer()
Access the player API instance.PlayerConfig
getPlayerConfig()
PlayerListeners
getPlayerListeners()
PlayerController.State
getPlayerState()
Returns the current player state.IPlayerView
getPlayerView()
long
getPosition()
Get the position in microseconds which is the playback position within the region of media currently available for playback.long
getPositionInPeriod()
Get the position in microseconds which is the playback position within the period of media currently available for playback.long
getPreBufferTime()
Gets an estimate of the absolute position in microseconds up to which data is buffered.List<RequestModifier>
getRequestModifiers()
Access the list of currently registered request modifier pluginsList<ResponseModifier>
getResponseModifiers()
Access the list of currently registered response modifier pluginsint
getSecondaryDisplay()
The secondary display setting, which is a bitmap ofSdkConsts.SECONDARY_DISPLAY_NEVER
,SdkConsts.SECONDARY_DISPLAY_ALLOW_UNPROTECTED_CONTENT
,SdkConsts.SECONDARY_DISPLAY_ALLOW_SECURE_DISPLAY
, andSdkConsts.SECONDARY_DISPLAY_ALLOW_ALWAYS
.long
getSeekRangeEndUs()
Get the end of the current seek range in microseconds orC.TIME_UNSET
.float
getSpeed()
SSLSocketFactory
getSSLSocketFactory()
Provides access to previously setSSLSocketFactory
SubtitlesStyle
getSubtitlesStyle()
SubtitleTrack
getSubtitleTrack()
List<SubtitleTrack>
getSubtitleTracks()
List<ThumbnailDataTrack>
getThumbnailTracks()
Returns a list of thumbnail track assets found in the opened DASH manifest.Timeline
getTimeline()
Returns the currentTimeline
.TrickplayConfiguration
getTrickplayConfiguration()
Returns the currentTrickplayConfiguration
VideoFilterConfiguration
getVideoFilterConfiguration()
List<VideoTrackQuality>
getVideoQualities()
VideoTrackQuality
getVideoQuality()
int
getVideoQualityMode()
Point
getVideoSizeFilter()
Deprecated.VideoTrack
getVideoTrack()
Returns the current video track.List<VideoTrack>
getVideoTracks()
Returns a list of video tracks.float
getVolume()
long
getWindowPositionInFirstPeriod()
The position of the start of the current window relative to the start of the first period belonging to it, in microseconds.boolean
isBackgrounded()
boolean
isCatchingUp()
boolean
isHdPlaybackEnabled()
Returns true if this controllers filter setting allows HD content playback.boolean
isLive()
Returns true if the live stream is currently played otherwise falseboolean
isLoopingEnabled()
Returns true if looping is enables and the player will automatically restart the playback on finish.boolean
isPlaying()
Returns true if the player is currently playingboolean
isPlayWhenReady()
Returns true if the player will start playing as soon as it fills enough buffer.boolean
isSeeking()
static boolean
isSupportedAudioCodec(String codec)
boolean
isTrickplayMode()
void
movePlayerListeners(PlayerController playerController)
Migrates all the listeners from this PlayerController to the given one.void
open(Bundle bundle)
This method takes aBundle
and extracts the information to create aPlayerConfig
from the bundle.void
open(PlayerConfig playerConfig)
Opens the given URL to the video.void
openState(Bundle bundle)
Opens the {link PlayerController} with the givenBundle
which is the saved state obtained withsaveState(Bundle)
void
pause()
Stop playervoid
play()
Start playerMap<String,String>
queryKeyStatus()
Queries the Key Status for the currently loaded session.Map<String,String>
queryKeyStatus(TrackRendererPlugin.Type trackType)
Queries the Key Status for the currently active session.void
registerDrmSession(DrmLicenseManager drmSessionManager)
INTERNAL: Register a drm session manager that is in use with this controllervoid
release()
Release the player instance and reset the underlying player model.void
releaseWithException(CastlabsPlayerException exception)
void
removeAudioRendererListener(AudioRendererListener listener)
Remove an audio renderer listenervoid
removeCatchupListener(CatchupListener listener)
Remove a Catchup listenervoid
removeDrmEventListener(DrmEventListener listener)
Remove a registeredDrmEventListener
void
removeFormatChangeListener(FormatChangeListener listener)
Remove the given listener.void
removeHttpListener(HttpListener listener)
Remove a HTTP listenervoid
removeMetadataListener(MetadataListener listener)
Remove the given listener.void
removePeriodChangedListener(PeriodChangedListener listener)
Remove the given listener.void
removePlayerControllerListener(PlayerControllerListener listener)
Remove the given listener.void
removePlayerListener(PlayerListener listener)
Remove a registeredPlayerListener
void
removePlayerModelFilter(PlayerModelFilter filter)
Removes aPlayerModelFilter
previously added withaddPlayerModelFilter(PlayerModelFilter)
.void
removeRequestModifier(RequestModifier modifier)
Remove a request modifier.void
removeResponseModifier(ResponseModifier modifier)
Remove a response modifier.void
removeStreamingEventListener(StreamingEventListener listener)
Remove the given listener.void
removeTimelineChangedListener(TimelineChangedListener listener)
Remove the given listener.void
removeTimelineListener(TimelineListener listener)
Remove the given listener.void
removeTrackSelectionListener(TrackSelectionListener listener)
Remove the given listener.void
removeVideoRendererListener(VideoRendererListener listener)
Remove a video renderer listenervoid
resetAudioFocus()
Resets the audio focus for the stream according to thePlayerConfig.audioAttributes
boolean
saveState(Bundle targetBundle)
Saves the state of this controller to the given target bundle.void
scanComponentViews(ViewGroup container)
Scans the given ViewGroup for specific PlayerControllerPlugin Views.void
seekWith(long offsetUs)
Sets the player to the new position by applying the offset to the current position i.e.void
setAbrConfiguration(AbrConfiguration abrConfiguration)
Set the ABR configuration used by the playervoid
setAnalyticsMetaData(AnalyticsMetaData analyticsMetaData)
Set the analytics meta-data.void
setAnalyticsSession(AnalyticsSession analyticsSession)
Set an already existing AnalyticsSession.void
setAudioFocusCallback(com.google.android.exoplayer2.AudioFocusCallback audioFocusCallback)
Sets theAudioFocusCallback
.void
setAudioTrack(AudioTrack track)
Sets the current audio track.void
setBackgrounded(boolean backgrounded)
This sends or restores the player from background playback.void
setBufferConfiguration(BufferConfiguration bufferConfiguration)
Set the buffer configuration for this controller.void
setComponentView(int viewId, View view)
Set a specific component View.void
setConfigurationProvider(ConfigurationProvider configurationProvider)
Sets the configuration provider e.g.void
setDataSourceFactory(DataSourceFactory dataSourceFactory)
Set theDataSourceFactory
that will be used to create connections.void
setDisableAnalytics(boolean disableAnalytics)
void
setExternalSourceSelector(ExternalSourceSelector externalSourceSelector)
Set theExternalSourceSelector
that will be used during CDN fallback Setnull
to disable the CDN fallbackvoid
setHdPlaybackEnabled(int filter)
Set the HD content filter criteria for this specific controller.void
setHlsKeyCache(HlsClearKeyCache hlsKeyCache)
Sets theHlsClearKeyCache
used for HLS Clearkey requests.void
setInitialPositionProvider(InitialPositionProvider provider)
Sets theInitialPositionProvider
.void
setInternalSourceSelectorFactory(com.google.android.exoplayer2.upstream.InternalSourceSelector.Factory sourceSelectorFactory)
Set theInternalSourceSelector.Factory
that will be used during CDN fallback Setnull
to use the defaultPlayerSDK.DEFAULT_INTERNAL_SOURCE_SELECTOR_FACTORY
void
setLiveConfiguration(LiveConfiguration liveConfiguration)
Set the live configuration for this controller.void
setLoopingEnabled(boolean loopingEnabled)
Enable/Disable loopingvoid
setMaxVideoSizeFilter(Point maxVideoSize)
void
setPeriodInfoProvider(PeriodInfoProvider periodInfoProvider)
Set thePeriodInfoProvider
that will be used to get additional information for the played period.void
setPlayerView(IPlayerView playerView)
Sets theIPlayerView
instance that is used to provide the surface and render the video.void
setPosition(long newPositionUs)
Seek the player to the new position in microseconds.void
setPosition(long newPositionUs, boolean sendToAnalytics)
Seek the player to the new position in microseconds Should not be used unless really needed as it may break the analytics metrics.void
setPositionInPeriod(long newPositionUs)
Seek the player to the new position in microseconds.void
setSecondaryDisplay(int secondaryDisplay)
The secondary display setting, which is a bitmap ofSdkConsts.SECONDARY_DISPLAY_NEVER
,SdkConsts.SECONDARY_DISPLAY_ALLOW_UNPROTECTED_CONTENT
,SdkConsts.SECONDARY_DISPLAY_ALLOW_SECURE_DISPLAY
, andSdkConsts.SECONDARY_DISPLAY_ALLOW_ALWAYS
.void
setSourceSelector(SourceSelector sourceSelector)
Deprecated.UsesetExternalSourceSelector(ExternalSourceSelector)
} Set theSourceSelector
that will be used during CDN fallbackvoid
setSpeed(float speed)
Enable fast-forward or slow motion playback by specifying the playback speed.void
setSSLSocketFactory(SSLSocketFactory sslSocketFactory)
Set customSSLSocketFactory
to be used in DRM and content requests.void
setSubtitlesStyle(SubtitlesStyle subtitlesStyle)
Allows you to set the desired captioning style that will be used during subtitle rendering.void
setSubtitleTrack(SubtitleTrack track)
Enables the given subtitle track.void
setSurface(Surface surface)
Set theSurface
that will be used to render video.boolean
setTrickplayConfiguration(TrickplayConfiguration trickplayConfiguration)
Sets whichTrickplayConfiguration
to use.void
setVideoFilterConfiguration(VideoFilterConfiguration videoFilter, VideoFilterConfiguration adsFilter)
void
setVideoQuality(VideoTrackQuality videoQuality)
Set the desired video quality or pass null to enable adaptive bitrate switching (default).void
setVideoTrack(VideoTrack track)
Sets the current video track.void
setVideoTrack(VideoTrack track, VideoTrackQuality quality)
Sets the current video track and a manually selected quality.void
setVolume(float volume)
Sets the output volume (gain) of the audio track.void
unsetComponentView(int viewId)
Remove the View linked to the provided view idvoid
unsetComponentViews()
Removes all the Component Viewsboolean
waitForMessages()
Queues a message to an arbitrary target and blocks until its delivered.
-
-
-
Field Detail
-
UNKNOWN_RENDERER
public static final int UNKNOWN_RENDERER
Identifies an unknown track- See Also:
- Constant Field Values
-
VIDEO_RENDERER
public static final int VIDEO_RENDERER
Identifies the video track- See Also:
- Constant Field Values
-
AUDIO_RENDERER
public static final int AUDIO_RENDERER
Identifies the audio track- See Also:
- Constant Field Values
-
TEXT_RENDERER
public static final int TEXT_RENDERER
Identifies the subtitle track- See Also:
- Constant Field Values
-
METADATA_RENDERER
public static final int METADATA_RENDERER
Identifies the metadata renderers for HLS ID3 metadata- See Also:
- Constant Field Values
-
DTS_RENDERER
public static final int DTS_RENDERER
Identifies the dts audio renderers- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PlayerController
public PlayerController(@NonNull Context context)
Create a new player controller using the given context- Parameters:
context
- the context
-
-
Method Detail
-
getComponent
@Nullable public <T> T getComponent(Class<T> type)
Returns the player component of the given type if it exists.- Type Parameters:
T
- The component- Parameters:
type
- The target type- Returns:
- The component or null
-
addPlayerListener
public void addPlayerListener(@NonNull PlayerListener listener)
Add aPlayerListener
.- Parameters:
listener
- the listener
-
removePlayerListener
public void removePlayerListener(@NonNull PlayerListener listener)
Remove a registeredPlayerListener
- Parameters:
listener
- the listener
-
addDrmEventListener
public void addDrmEventListener(@NonNull DrmEventListener listener)
Add aDrmEventListener
.- Parameters:
listener
- the listener
-
removeDrmEventListener
public void removeDrmEventListener(@NonNull DrmEventListener listener)
Remove a registeredDrmEventListener
- Parameters:
listener
- the listener
-
addStreamingEventListener
public void addStreamingEventListener(@NonNull StreamingEventListener listener)
Add a new event listener.- Parameters:
listener
- the listeners
-
removeStreamingEventListener
public void removeStreamingEventListener(@NonNull StreamingEventListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
addFormatChangeListener
public void addFormatChangeListener(@NonNull FormatChangeListener listener)
Add a new Format change listener.- Parameters:
listener
- the listener
-
removeFormatChangeListener
public void removeFormatChangeListener(@NonNull FormatChangeListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
addMetadataListener
public void addMetadataListener(@NonNull MetadataListener listener)
Add a new event listener to receive updates on ID3 Meta-Data tags from HLS streams.- Parameters:
listener
- the listener
-
addCustomDashEventListener
public void addCustomDashEventListener(@NonNull CustomDashEventListener listener)
Add a new event listener to receive custom DASH events- Parameters:
listener
- the listener
-
addTimelineListener
public void addTimelineListener(@NonNull TimelineListener listener)
Deprecated.Add a new event listener to receive updates on timeline and period changes- Parameters:
listener
- the listener
-
addTimelineChangedListener
public void addTimelineChangedListener(TimelineChangedListener listener)
Adds a listener to receive updates onTimeline
updates- Parameters:
listener
- the listener
-
addPeriodChangedListener
public void addPeriodChangedListener(PeriodChangedListener listener)
Adds a listener to receive updates onTimeline.Period
changes- Parameters:
listener
- the listener
-
addTrackSelectionListener
public void addTrackSelectionListener(@NonNull TrackSelectionListener listener)
Add a new event listener to receive updates related to track selection.- Parameters:
listener
- the listener
-
removeMetadataListener
public void removeMetadataListener(@NonNull MetadataListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
removeTimelineListener
public void removeTimelineListener(@NonNull TimelineListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
removeTimelineChangedListener
public void removeTimelineChangedListener(TimelineChangedListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
removePeriodChangedListener
public void removePeriodChangedListener(@NonNull PeriodChangedListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
addPlayerControllerListener
public void addPlayerControllerListener(@NonNull PlayerControllerListener listener)
Add a new player controller listener- Parameters:
listener
- the listeners
-
removePlayerControllerListener
public void removePlayerControllerListener(@NonNull PlayerControllerListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
removeTrackSelectionListener
public void removeTrackSelectionListener(@NonNull TrackSelectionListener listener)
Remove the given listener.- Parameters:
listener
- the listener
-
addVideoRendererListener
public void addVideoRendererListener(@NonNull VideoRendererListener listener)
Add a video renderer listener- Parameters:
listener
- The listener- Since:
- 4.2.4
-
removeVideoRendererListener
public void removeVideoRendererListener(@NonNull VideoRendererListener listener)
Remove a video renderer listener- Parameters:
listener
- The listener- Since:
- 4.2.4
-
addAudioRendererListener
public void addAudioRendererListener(@NonNull AudioRendererListener listener)
Add an audio renderer listener- Parameters:
listener
- The listener- Since:
- 4.2.25
-
removeAudioRendererListener
public void removeAudioRendererListener(@NonNull AudioRendererListener listener)
Remove an audio renderer listener- Parameters:
listener
- The listener- Since:
- 4.2.25
-
addCatchupListener
public void addCatchupListener(@NonNull CatchupListener listener)
Add a Catchup listener- Parameters:
listener
- The listener- Since:
- 4.2.45
-
removeCatchupListener
public void removeCatchupListener(@NonNull CatchupListener listener)
Remove a Catchup listener- Parameters:
listener
- The listener- Since:
- 4.2.45
-
addHttpListener
public void addHttpListener(@NonNull HttpListener listener)
Add a HTTP listener- Parameters:
listener
- The listener- Since:
- 4.2.45
-
removeHttpListener
public void removeHttpListener(@NonNull HttpListener listener)
Remove a HTTP listener- Parameters:
listener
- The listener- Since:
- 4.2.45
-
addRequestModifier
public void addRequestModifier(@NonNull RequestModifier modifier)
Add a request modifier. Please not that you need to call this before callingopen(Bundle)
if you want to modify Manifest requests.- Parameters:
modifier
- The modifier
-
removeRequestModifier
public void removeRequestModifier(@NonNull RequestModifier modifier)
Remove a request modifier.- Parameters:
modifier
- The modifier
-
getRequestModifiers
public List<RequestModifier> getRequestModifiers()
Access the list of currently registered request modifier plugins- Returns:
- The list of currently registered request modifier plugins
-
addResponseModifier
public void addResponseModifier(@NonNull ResponseModifier modifier)
Add a response modifier.- Parameters:
modifier
- The modifier- Since:
- 4.2.0
-
removeResponseModifier
public void removeResponseModifier(@NonNull ResponseModifier modifier)
Remove a response modifier.- Parameters:
modifier
- The modifier- Since:
- 4.2.0
-
getResponseModifiers
public List<ResponseModifier> getResponseModifiers()
Access the list of currently registered response modifier plugins- Returns:
- The list of currently registered response modifier plugins
- Since:
- 4.2.0
-
getSecondaryDisplay
public int getSecondaryDisplay()
The secondary display setting, which is a bitmap ofSdkConsts.SECONDARY_DISPLAY_NEVER
,SdkConsts.SECONDARY_DISPLAY_ALLOW_UNPROTECTED_CONTENT
,SdkConsts.SECONDARY_DISPLAY_ALLOW_SECURE_DISPLAY
, andSdkConsts.SECONDARY_DISPLAY_ALLOW_ALWAYS
. The setting is initialised toPlayerSDK.SECONDARY_DISPLAY
at construction time.- Returns:
- The secondary display setting
-
setSecondaryDisplay
public void setSecondaryDisplay(int secondaryDisplay)
The secondary display setting, which is a bitmap ofSdkConsts.SECONDARY_DISPLAY_NEVER
,SdkConsts.SECONDARY_DISPLAY_ALLOW_UNPROTECTED_CONTENT
,SdkConsts.SECONDARY_DISPLAY_ALLOW_SECURE_DISPLAY
, andSdkConsts.SECONDARY_DISPLAY_ALLOW_ALWAYS
. The setting is initialised toPlayerSDK.SECONDARY_DISPLAY
at construction time. This setting is checked when playback is initialized or a display is connected and an error of typeCastlabsPlayerException.TYPE_SECONDARY_DISPLAY
will raised if the setting is not compatible with the current display configuration. The player controller will also register a listener and raise an error when the display configuration changes during playback. As DRM licenses can prevent playback on secondary, insecure, or remote screens. The player will, by default, add a listener to theMediaRouter
system service in order to process changes in display configurations. It's been observed that, in some specific devices, theMediaRouter
service can't be acquired. In such cases, it's recommended to set this flag toSdkConsts.SECONDARY_DISPLAY_ALLOW_ALWAYS
. Note that disabling these screen configuration enforcements might allow playback in circumstances what would otherwise be prevented by the license. If set toSdkConsts.SECONDARY_DISPLAY_ALLOW_ALWAYS
and playback is opened, no display configuration checks will take place even if this field is updated afterwards.- Parameters:
secondaryDisplay
- The secondary display setting
-
getDataSourceFactory
@NonNull public DataSourceFactory getDataSourceFactory()
Provides access to theDataSourceFactory
. You can use this factory to provide additional header and query parameters that will be send with each request.- Returns:
- Returns the instance of the
DataSourceFactory
-
setDataSourceFactory
public void setDataSourceFactory(@Nullable DataSourceFactory dataSourceFactory)
Set theDataSourceFactory
that will be used to create connections. This factory is responsible to manager request and query parameters, so please make sure that you only set additional parameters after you set any custom data source.- Parameters:
dataSourceFactory
- the factory instance
-
getSSLSocketFactory
@Nullable public SSLSocketFactory getSSLSocketFactory()
Provides access to previously setSSLSocketFactory
- Returns:
SSLSocketFactory
ornull
when unknown
-
setSSLSocketFactory
public void setSSLSocketFactory(@Nullable SSLSocketFactory sslSocketFactory)
Set customSSLSocketFactory
to be used in DRM and content requests. Takes precedence overPlayerSDK.SSL_KEY_STORE
- Parameters:
sslSocketFactory
-SSLSocketFactory
-
getBandwidthMeterWrapper
@NonNull public BandwidthMeterWrapper getBandwidthMeterWrapper()
The bandwidth meter wrapper- Returns:
- bandwidthMeter
-
setSourceSelector
@Deprecated public void setSourceSelector(@Nullable SourceSelector sourceSelector)
Deprecated.UsesetExternalSourceSelector(ExternalSourceSelector)
} Set theSourceSelector
that will be used during CDN fallback- Parameters:
sourceSelector
- The CDN selector
-
setExternalSourceSelector
public void setExternalSourceSelector(@Nullable ExternalSourceSelector externalSourceSelector)
Set theExternalSourceSelector
that will be used during CDN fallback Setnull
to disable the CDN fallback- Parameters:
externalSourceSelector
- The CDN selector
-
setInternalSourceSelectorFactory
public void setInternalSourceSelectorFactory(@Nullable com.google.android.exoplayer2.upstream.InternalSourceSelector.Factory sourceSelectorFactory)
Set theInternalSourceSelector.Factory
that will be used during CDN fallback Setnull
to use the defaultPlayerSDK.DEFAULT_INTERNAL_SOURCE_SELECTOR_FACTORY
- Parameters:
sourceSelectorFactory
- TheInternalSourceSelector.Factory
-
setConfigurationProvider
public void setConfigurationProvider(@Nullable ConfigurationProvider configurationProvider)
Sets the configuration provider e.g. when Widevine license renewal is enabled viaDrmTodayConfiguration.Builder.renewalThreshold(long, TimeUnit)
- Parameters:
configurationProvider
- The configuration provider
-
setPeriodInfoProvider
public void setPeriodInfoProvider(@Nullable PeriodInfoProvider periodInfoProvider)
Set thePeriodInfoProvider
that will be used to get additional information for the played period. Use it to enable period-based ads handling.- Parameters:
periodInfoProvider
- ThePeriodInfoProvider.PeriodInfo
provider
-
getAdInterface
@NonNull public AdInterface getAdInterface()
Gets access toAdInterface
APIs- Returns:
AdInterface
instance
-
getAdClientInterface
@NonNull public AdClientInterface getAdClientInterface()
Gets access toAdClientInterface
APIs- Returns:
AdClientInterface
instance
-
setDisableAnalytics
public void setDisableAnalytics(boolean disableAnalytics)
-
isBackgrounded
public boolean isBackgrounded()
- Returns:
- True if player is currently playing audio only in the background
-
setBackgrounded
public void setBackgrounded(boolean backgrounded)
This sends or restores the player from background playback. If backgrounded, video playback is disabled and the current surface is removed from the player. The visual components can be disposed after this call and audio will continue in the background. If recovering from background, the last video track is re-enabled and the surface is reattached to the player. If you intend to use background playback, please consider using thePlayerService
which will handle the background playback session for you. In that case, you will not need to call this method explicitly.- Parameters:
backgrounded
- background or restore playback
-
getMainHandler
@NonNull public Handler getMainHandler()
- Returns:
- the main handler of this controller
-
getLiveStartTime
public long getLiveStartTime()
Get the live start time in microseconds since the epoch or -1 if unknown or not applicable. The live start time is defined as start time of the region of media currently available for playback. The value is updated each time the available region of media is updated. Shall be used for informational purposes only.- Returns:
- liveStartTimeUs the live start time in microseconds if known or -1 otherwise
-
getAudioFocusCallback
public com.google.android.exoplayer2.AudioFocusCallback getAudioFocusCallback()
-
getWindowPositionInFirstPeriod
public long getWindowPositionInFirstPeriod()
The position of the start of the current window relative to the start of the first period belonging to it, in microseconds. Shall be used for informational purposes only.- Returns:
- The position of the start of the current window or -1 if unknown or not applicable
-
getPosition
public long getPosition()
Get the position in microseconds which is the playback position within the region of media currently available for playback. For live streamsisLive()
the current position since epoch can be obtained asgetLiveStartTime()
+getPosition()
- Returns:
- positionUs the position in microseconds
-
getPositionInPeriod
public long getPositionInPeriod()
Get the position in microseconds which is the playback position within the period of media currently available for playback. This value for live streams may be different to whatgetPosition()
returns since it is possible (and likely) to have live window smaller than the Period, which usually starts when stream started.- Returns:
- positionUs the position inside the current Period in microseconds
-
setPositionInPeriod
public void setPositionInPeriod(long newPositionUs)
Seek the player to the new position in microseconds. The indicated position is interpreted as position in the current Period.The corresponding event will be sent to analytics session (if any)
- Parameters:
newPositionUs
- the new position in microseconds for the current Period
-
setPosition
public void setPosition(long newPositionUs)
Seek the player to the new position in microseconds. The corresponding event will be sent to analytics session (if any)- Parameters:
newPositionUs
- the new position in microseconds
-
setPosition
public void setPosition(long newPositionUs, boolean sendToAnalytics)
Seek the player to the new position in microseconds Should not be used unless really needed as it may break the analytics metrics.- Parameters:
newPositionUs
- the new position in microsecondssendToAnalytics
- flag if the event shall be sent to analytics session
-
seekWith
public void seekWith(long offsetUs)
Sets the player to the new position by applying the offset to the current position i.e. with the negative offset the playback goes backward and with the positive one goes forward. The resulting playback position is clipped with zero and the content duration.- Parameters:
offsetUs
- The offset to be applied to the current position
-
setTrickplayConfiguration
public boolean setTrickplayConfiguration(@NonNull TrickplayConfiguration trickplayConfiguration)
Sets whichTrickplayConfiguration
to use. Note that in order to apply this configuration you should alsoenable
it.
-
getTrickplayConfiguration
@NonNull public TrickplayConfiguration getTrickplayConfiguration()
Returns the currentTrickplayConfiguration
- Returns:
- the current TrickplayConfiguration
-
getHlsKeyCache
@Nullable public HlsClearKeyCache getHlsKeyCache()
Returns the currentHlsClearKeyCache
used for HLS Clearkey requests. If no Cache wasset
prior to playback open, a new emptyMemoryHlsClearKeyCache
cache will be created.- Returns:
- the cache
-
setHlsKeyCache
public void setHlsKeyCache(@Nullable HlsClearKeyCache hlsKeyCache)
Sets theHlsClearKeyCache
used for HLS Clearkey requests. Must be set before theopen(PlayerConfig)
call to take effect.- Parameters:
hlsKeyCache
- the cache to set
-
isTrickplayMode
public boolean isTrickplayMode()
- Returns:
- whether the player is currently in trickplay mode or not.
-
isCatchingUp
public boolean isCatchingUp()
-
enableTrickplayMode
public void enableTrickplayMode(boolean enable)
Enables or disables trickplay playback.- Parameters:
enable
- enable flag
-
getSpeed
public float getSpeed()
- Returns:
- The current playback seekSpeed
-
setMaxVideoSizeFilter
public void setMaxVideoSizeFilter(@Nullable Point maxVideoSize)
Sets the current maximum video size filter, while respecting ABR configuration. Can also be set withSdkConsts.INTENT_VIDEO_SIZE_FILTER
. Ifnull
will revert back toPlayerSDK.VIDEO_SIZE_FILTER
.- Parameters:
maxVideoSize
- The current maximum video size filter.
-
setVideoFilterConfiguration
public void setVideoFilterConfiguration(@Nullable VideoFilterConfiguration videoFilter, @Nullable VideoFilterConfiguration adsFilter)
-
addPlayerModelFilter
public void addPlayerModelFilter(@NonNull PlayerModelFilter filter)
Adds aPlayerModelFilter
. This allows arbitratry track filtering beyond the capabilities of thevideoFilterConfiguration
.- Parameters:
filter
- the filter to add.
-
removePlayerModelFilter
public void removePlayerModelFilter(@NonNull PlayerModelFilter filter)
Removes aPlayerModelFilter
previously added withaddPlayerModelFilter(PlayerModelFilter)
.- Parameters:
filter
- the filter to remove.
-
setSpeed
public void setSpeed(float speed)
Enable fast-forward or slow motion playback by specifying the playback speed. When the requested speed is different from 1 then the audio is disabled and otherwise is enabled automatically. Note that setting speed for the online playback with high video quality may result in video stuttering/lagging and it is advised to disable the ABR by setting one of the low video qualitiessetVideoQuality(VideoTrackQuality)
before changing the playback speed.- Parameters:
speed
- The playback speed
-
addSubtitleTrack
public void addSubtitleTrack(@NonNull String url, @NonNull String mimeType, @Nullable String language, @Nullable String name)
Add a subtitles track to be side-loaded when content is opened. Note that you will need to call this method before callingopen(PlayerConfig)
to successfully add a subtitles track.- Parameters:
url
- the encoded URL to the subtitles filemimeType
- the mime type, i.e text/vtt. This shoudl be one ofSdkConsts.MIME_TYPE_TTML
,SdkConsts.MIME_TYPE_VTT
,SdkConsts.MIME_TYPE_SRT
orSdkConsts.MIME_TYPE_CEA608
language
- optional two letter language code, i.e. "en"name
- optional track nam
-
addThumbnailTrack
public void addThumbnailTrack(ThumbnailDataTrack thumbnailDataTrack)
Adds a thumbnail track. You should not use this method to sideload thumbnail tracks. To do so, add the thumbnails info in theIntent
that's sent toopen(Bundle)
as described in- Parameters:
thumbnailDataTrack
-
-
getSubtitleTracks
@NonNull public List<SubtitleTrack> getSubtitleTracks()
- Returns:
- A list of the currently registered subtitles
-
getSubtitleTrack
@Nullable public SubtitleTrack getSubtitleTrack()
- Returns:
- The currently active subtitle track or null if no subtitle track is active
-
setSubtitleTrack
public void setSubtitleTrack(@Nullable SubtitleTrack track)
Enables the given subtitle track. You can passnull
to disable subtitles- Parameters:
track
- the subtitle track or null to disable subtitles
-
setSubtitlesStyle
public void setSubtitlesStyle(@Nullable SubtitlesStyle subtitlesStyle)
Allows you to set the desired captioning style that will be used during subtitle rendering. This will override any styling that is specified by the subtitle content (i.e. TTML with styles) for all style properties where the default setting is explicitly overwritten (see for exampleSubtitlesStyle.hasForegroundColor
and the otherhasXXX
flags on the style). This method can be used for example, to set the user specified accessibility settings required for FCC compliance. You can passnull
to use the default styles specified in the content- Parameters:
subtitlesStyle
- object containing the style settings or null to use default
-
getSubtitlesStyle
@Nullable public SubtitlesStyle getSubtitlesStyle()
-
getAudioTrack
@Nullable public AudioTrack getAudioTrack()
Returns the current audio track. This can be null if no audio track is available.- Returns:
- track the currently selected audio track
-
setAudioTrack
public void setAudioTrack(@Nullable AudioTrack track)
Sets the current audio track. You can passnull
to disable audio playback.- Parameters:
track
- the audio track
-
getAudioTracks
@NonNull public List<AudioTrack> getAudioTracks()
Returns a list of audio track assets found in the opened movie meta data. *NOTE* that you have to callopen(PlayerConfig)
before you can call this method. From 3.0.0, DTS and Dolby tracks are supported via passthrough. This method will return all the audio tracks. It is recommended to test every audio track withAudioTrack.isSupportedCodec()
to avoid possible playback issues.- Returns:
- audioAssets list of available audio assets
-
getThumbnailTracks
@NonNull public List<ThumbnailDataTrack> getThumbnailTracks()
Returns a list of thumbnail track assets found in the opened DASH manifest. *NOTE* that you have to callopen(PlayerConfig)
before you can call this method.- Returns:
- list of available thumbnails
-
getVideoTrack
@Nullable public VideoTrack getVideoTrack()
Returns the current video track. This can be null if no video track is available.- Returns:
- track the currently selected video track
-
setVideoTrack
public void setVideoTrack(@Nullable VideoTrack track)
Sets the current video track. You can passnull
to disable video playback. Note that this is not the same assetVideoQuality(VideoTrackQuality)
and in most cases you will only have one video track with multiple qualities.- Parameters:
track
- the video track
-
setVideoTrack
public void setVideoTrack(@Nullable VideoTrack track, @Nullable VideoTrackQuality quality)
Sets the current video track and a manually selected quality. You can passnull
to disable video playback. Note that this is not the same assetVideoQuality(VideoTrackQuality)
and in most cases you will only have one video track with multiple qualities.- Parameters:
track
- the video trackquality
- the quality
-
getTimeline
@NonNull public Timeline getTimeline()
Returns the currentTimeline
. Can be empty if there's no loaded content.- Returns:
- the current
Timeline
-
getVideoTracks
@NonNull public List<VideoTrack> getVideoTracks()
Returns a list of video tracks.- Returns:
- videoTracks list of available video tracks or an empty list
-
getVideoQualities
@NonNull public List<VideoTrackQuality> getVideoQualities()
- Returns:
- List of
VideoTrackQuality
s for the currently active video track in decreasing bitrate order
-
getVideoQuality
@Nullable public VideoTrackQuality getVideoQuality()
- Returns:
- The current displayed video quality or
null
-
setVideoQuality
public void setVideoQuality(@Nullable VideoTrackQuality videoQuality)
Set the desired video quality or pass null to enable adaptive bitrate switching (default). Note that passing a quality here will disable adaptive bitrate switching and the playback will stay in the given quality. Also, any existinginitial track selection
will be lost.- Parameters:
videoQuality
- the quality
-
getVideoQualityMode
public int getVideoQualityMode()
- Returns:
- The current quality mode. Either
SdkConsts.VIDEO_QUALITY_ADAPTIVE
orSdkConsts.VIDEO_QUALITY_MANUAL
-
getAbrConfiguration
@NonNull public AbrConfiguration getAbrConfiguration()
Returns the current ABR configuration- Returns:
- The ABR configuration
-
getVideoSizeFilter
@NonNull public Point getVideoSizeFilter()
Deprecated.Returns the current video size filter- Returns:
- The current video size filter
-
getVideoFilterConfiguration
@NonNull public VideoFilterConfiguration getVideoFilterConfiguration()
-
setAbrConfiguration
public void setAbrConfiguration(@Nullable AbrConfiguration abrConfiguration)
Set the ABR configuration used by the player- Parameters:
abrConfiguration
- The Abr configuration or null to reset to the default
-
getMediaCodecSelector
@NonNull public com.google.android.exoplayer2.mediacodec.MediaCodecSelector getMediaCodecSelector()
-
getPlayerConfig
@Nullable public PlayerConfig getPlayerConfig()
- Returns:
- playerConfig the current playback state or null if no content was loaded yet
- Since:
- 3.0.0
-
getOfflinePath
@Nullable public String getOfflinePath()
Gets the local path to the currently played content if it is played offline, otherwisenull
- Returns:
- The local path to the offline content or
null
otherwise
-
getPreBufferTime
public long getPreBufferTime()
Gets an estimate of the absolute position in microseconds up to which data is buffered.- Returns:
- An estimate of the absolute position in microseconds up to which data is buffered, or 0 if no estimate is available.
-
getBufferSizeBytes
public int getBufferSizeBytes()
Return the current buffer size in bytes- Returns:
- The buffer size in bytes
- Since:
- 4.2.6
-
getBufferSizeTime
public long getBufferSizeTime()
Return the current buffer size ahead of the playhead in media time microseconds- Returns:
- The buffer size ahead in microseconds
- Since:
- 4.2.6
-
getBufferedPosition
public long getBufferedPosition()
Returns an estimate of the position in the current content window or ad up to which data is buffered, in microseconds.- Returns:
- The buffered position in microseconds
- Since:
- 4.2.47
-
getBufferedPercentage
public int getBufferedPercentage()
Returns an estimate of the percentage in the current content window or ad up to which data is buffered, or 0 if no estimate is available.- Returns:
- The buffered percentage
- Since:
- 4.2.47
-
getMaxBufferSizeBytes
public int getMaxBufferSizeBytes()
Return the maximum buffer size in bytes- Returns:
- The max buffer size in bytes
- Since:
- 4.2.5
-
getAudioAttributes
@NonNull public com.google.android.exoplayer2.audio.AudioAttributes getAudioAttributes()
-
getBackBufferTime
public long getBackBufferTime()
Returns the oldest position that still has buffered content, in microseconds.If a seek is performed to this position or further, no media should be re-downloaded as it is still present in the buffer.
- Returns:
- the oldest position that still has buffered content, in microseconds.
-
isPlaying
public boolean isPlaying()
Returns true if the player is currently playing- Returns:
- true if player is currently playing
-
isSeeking
public boolean isSeeking()
- Returns:
- true if the player is seeking to a new position after a call to
setPosition(long)
-
isPlayWhenReady
public boolean isPlayWhenReady()
Returns true if the player will start playing as soon as it fills enough buffer.- Returns:
- true if the player will start playing as soon as it fills enough buffer.
-
getDuration
public long getDuration()
Get the duration in microseconds of a region of media currently available for playback (including both live and static streams) or -1 if no duration is available for the current stream. Returns a value < 0 if no duration information at all is available, for example if no content is loaded yet. UseisLive()
to check either the content is live or not.- Returns:
- duration duration in microseconds or -1
-
getSeekRangeEndUs
public long getSeekRangeEndUs()
Get the end of the current seek range in microseconds orC.TIME_UNSET
.- Returns:
- The end of the current seek range in microseconds or
C.TIME_UNSET
.
-
getVolume
public float getVolume()
- Returns:
- The current volume (gain) setting as a value between 0 and 1
-
setVolume
public void setVolume(float volume)
Sets the output volume (gain) of the audio track. A value of 0.0 results in zero gain (silence), and a value of 1.0 means unity gain (signal unchanged). The default value is 1.0 meaning unity gain.- Parameters:
volume
- the output gain between 0.0 (silence) and 1.0 (signal unchanged)- Throws:
IllegalArgumentException
- in case the volume not 0 <= volume <= 1
-
getPath
@Nullable public String getPath()
Returns the path set in this controller or null- Returns:
- path the path or null
-
getPlayerState
@NonNull public PlayerController.State getPlayerState()
Returns the current player state.- Returns:
- the player state
- Since:
- 3.0.0
-
getPlayer
@Nullable public com.google.android.exoplayer2.ExoPlayer getPlayer()
Access the player API instance.- Returns:
- player the player instance
-
isLoopingEnabled
public boolean isLoopingEnabled()
Returns true if looping is enables and the player will automatically restart the playback on finish.- Returns:
- true if looping is enabled
-
setLoopingEnabled
public void setLoopingEnabled(boolean loopingEnabled)
Enable/Disable looping- Parameters:
loopingEnabled
- enable or disable looping
-
getAnalyticsSession
@Nullable public AnalyticsSession getAnalyticsSession()
Get the current analytics session if there is one. Please note that the session will be initialized only when content was loaded usingopen(Bundle)
oropen(PlayerConfig)
.- Returns:
- The analytics session or null
- See Also:
AnalyticsSession.detachFromController()
-
setAnalyticsSession
public void setAnalyticsSession(@Nullable AnalyticsSession analyticsSession)
Set an already existing AnalyticsSession. This should be called beforeopen(Bundle)
. Setting null willdetach
the Session, if any. The caller is responsible to release the session if not reusing.- Parameters:
analyticsSession
- AnalyticsSession to use in this Player Controller. Should be gotten with thegetAnalyticsSession()
before the player controller is disposed. If null, it will unset any Analytics sessions.
-
getAnalyticsMetaData
@Nullable public AnalyticsMetaData getAnalyticsMetaData()
- Returns:
- Get the analytics meta data associated with the controller or null if no data are set
-
setAnalyticsMetaData
public void setAnalyticsMetaData(@NonNull AnalyticsMetaData analyticsMetaData)
Set the analytics meta-data. If you are usingopen(PlayerConfig)
and noBundle
to start playback, you need to call this method before you start playback to set the required meta-data parameters for the playback session. Without the meta-data object in place, analytics integration will not work since the different analytics integrations require certain mandatory parameters to be set. The documentation and API docs for the different analytics platforms contain information which parameters are mandatory.- Parameters:
analyticsMetaData
- The meta-data
-
open
public void open(@NonNull Bundle bundle)
This method takes aBundle
and extracts the information to create aPlayerConfig
from the bundle. The following bundle keys are queried to create the playback state: The following keys will be checked:SdkConsts.INTENT_URL
expects a String (mandatory)SdkConsts.INTENT_START_PLAYING
expects a Boolean (default: true)SdkConsts.INTENT_POSITION_TO_PLAY
expects a Long (default: 0)SdkConsts.INTENT_DRM_CONFIGURATION
expects aDrmConfiguration
(default: null)SdkConsts.INTENT_AUDIO_TRACK_GROUP_IDX
expects aInteger
(default: 0 to play the first track)SdkConsts.INTENT_SUBTITLE_TRACK_GROUP_IDX
expects aInteger
(default: -1 to disable subtitles)SdkConsts.INTENT_CONTENT_TYPE
expects aInteger
(default:SdkConsts.CONTENT_TYPE_UNKNOWN
to auto-detect). Allowed values are one ofSdkConsts.CONTENT_TYPE_UNKNOWN
,SdkConsts.CONTENT_TYPE_DASH
,SdkConsts.CONTENT_TYPE_HLS
,SdkConsts.CONTENT_TYPE_SMOOTHSTREAMING
, orSdkConsts.CONTENT_TYPE_MP4
SdkConsts.INTENT_AUDIO_VOLUME
expects aFloat
with a value 0 <= value <= 1SdkConsts.INTENT_SECONDARY_DISPLAY
expects aInteger
and defaults to the value ofgetSecondaryDisplay()
SdkConsts.INTENT_HD_CONTENT_FILTER
expects aInteger
and defaults to the value ofPlayerSDK.PLAYBACK_HD_CONTENT
SdkConsts.INTENT_VIDEO_SIZE_FILTER
expects aPoint
and defaults to the value ofPlayerSDK.VIDEO_SIZE_FILTER
SdkConsts.INTENT_VIDEO_CODEC_FILTER
expects aInteger
and defaults to the value ofPlayerSDK.VIDEO_CODEC_FILTER
SdkConsts.INTENT_ENABLE_LOOPING
expects aBoolean
and if true, enables loopingSdkConsts.INTENT_ANALYTICS_DATA
expects aAnalyticsMetaData
object and is required if you are using one of the analytics pluginsSdkConsts.INTENT_BUFFER_CONFIGURATION
expects aBufferConfiguration
object and can be used to teak the player bufferSdkConsts.INTENT_ABR_CONFIGURATION
expects aAbrConfiguration
object and can be used to teak the players ABR behaviourSdkConsts.INTENT_USER_ID
expects aString
SdkConsts.INTENT_LIVE_CONFIGURATION
expects aLiveConfiguration
object and is used to tweak live-related params
SdkConsts.INTENT_QUERY_PARAMS_BUNDLE
andSdkConsts.INTENT_HEADER_PARAMS_BUNDLE
to configure and add query and header parameters that will be send with each request. This can for example be used to add tokens when remote resources are requested. In both cases, the bundle needs to reference anotherBundle
instance that is then used as a key/value store for the query or header parameters. You can also useSdkConsts.INTENT_SUBTITLE_BUNDLE_ARRAYLIST
to side-load additional subtitle tracks through the bundle. Use the key to store anArrayList
ofBundle
instances that specify side loaded tracks. Useintent.putParcelableArrayListExtra(SdkConsts.INTENT_SUBTITLE_BUNDLE_ARRAYLIST, ...);
to add the list of bundles with the subtitle track information. A full example of this looks like:ArrayList<Bunde> subtitles = new ArrayList<>(); Bundle bundle = new Bundle(); bundle.putString(SdkConsts.INTENT_SUBTITLE_URL, "https://my.com/subtitle.ttml"); bundle.putString(SdkConsts.INTENT_SUBTITLE_MIME_TYPE, SdkConsts.MIME_TYPE_TTML); bundle.putString(SdkConsts.INTENT_SUBTITLE_LANGUAGE, "en"); bundle.putString(SdkConsts.INTENT_SUBTITLE_NAME, "Side-loaded"); subtitles.add(bundle); intent.putExtra(SdkConsts.INTENT_SUBTITLE_BUNDLE_ARRAYLIST, subtitles);
- Parameters:
bundle
- the bundle- Since:
- 3.0.0
- See Also:
PlayerConfig.Builder.fromBundle(Bundle)
-
open
public void open(@NonNull PlayerConfig playerConfig)
Opens the given URL to the video. You can specify a path to a local file here, but in this case, please note that the path *needs* to be absolute. The path is treated as a URL and a protocol is expected. If no protocol is specified, the `file://` protocol is assumed and prepended to the given path. If you are using an Analytics Plugin, make sure you usesetAnalyticsMetaData(AnalyticsMetaData)
to set the required meta-data before calling this method.- Parameters:
playerConfig
- the desired Player configuration
-
play
public void play()
Start player
-
pause
public void pause()
Stop player
-
destroy
public void destroy()
Call this method when the activity that displays the video player is destroyed. This releases the player the resources allocated by this controller. This call will also remove all callbacks, and in case there's aplayerView
, the PlayerController will be removed from it.- Since:
- 1.2.0
-
release
public void release()
Release the player instance and reset the underlying player model. You will need to callopen(Bundle)
oropen(PlayerConfig)
to restart playback.
-
releaseWithException
public void releaseWithException(@Nullable CastlabsPlayerException exception)
-
getKeyStore
@Nullable public static KeyStore getKeyStore()
Returns theKeyStore
that will be used to store offline IDs or null if no store is configured. This is the same asPlayerSDK.DEFAULT_KEY_STORE
.- Returns:
- The key store or null
-
isHdPlaybackEnabled
public boolean isHdPlaybackEnabled()
Returns true if this controllers filter setting allows HD content playback.- Returns:
- True if general HD content playback is enabled
-
setHdPlaybackEnabled
public void setHdPlaybackEnabled(int filter)
Set the HD content filter criteria for this specific controller. The methods accepts a bit field that is constructed from the values ofSdkConsts.ALLOW_HD_CLEAR_CONTENT
,SdkConsts.ALLOW_HD_DRM_SECURE_MEDIA_PATH
,SdkConsts.ALLOW_HD_DRM_ROOT_OF_TRUST
,SdkConsts.ALLOW_HD_NEVER
, andSdkConsts.ALLOW_HD_DRM_SOFTWARE
. The default value is the setting forPlayerSDK.PLAYBACK_HD_CONTENT
. *- Parameters:
filter
- The HD content filter setting
-
getBufferConfiguration
@NonNull public BufferConfiguration getBufferConfiguration()
Returns the buffer configuration of this controller- Returns:
- The buffer configuration
-
getLiveConfiguration
@NonNull public LiveConfiguration getLiveConfiguration()
Returns the live configuration of this controller- Returns:
- The Live configuration
-
setBufferConfiguration
public void setBufferConfiguration(@Nullable BufferConfiguration bufferConfiguration)
Set the buffer configuration for this controller. The buffer configuration can also be changed at runtime.- Parameters:
bufferConfiguration
- The buffer configuration
-
setLiveConfiguration
public void setLiveConfiguration(@Nullable LiveConfiguration liveConfiguration)
Set the live configuration for this controller. You need to call this before you callopen(Bundle)
to have an effect on the playback.- Parameters:
liveConfiguration
- The live configuration
-
setInitialPositionProvider
public void setInitialPositionProvider(@Nullable InitialPositionProvider provider)
Sets theInitialPositionProvider
.- Parameters:
provider
- the provider to set
-
getNetworkConfiguration
@NonNull public NetworkConfiguration getNetworkConfiguration()
- Returns:
- The current network configuration
-
isLive
public boolean isLive()
Returns true if the live stream is currently played otherwise false- Returns:
- True if the live stream is currently played otherwise false
-
getLiveEdgeLatency
public int getLiveEdgeLatency()
For live streams, the number of milliseconds that the playback should lag behind the "live edge" (i.e. the end of the most recently defined media in the manifest).- Returns:
- liveEdgeLatencyMs The time in milliseconds the player lags behind the live edge
-
openState
public void openState(@NonNull Bundle bundle)
Opens the {link PlayerController} with the givenBundle
which is the saved state obtained withsaveState(Bundle)
- Parameters:
bundle
- TheBundle
to open thePlayerController
with
-
saveState
public boolean saveState(@NonNull Bundle targetBundle)
Saves the state of this controller to the given target bundle. This will store the playback state and all intent parameters that are required to restore the state of this controller usingopen(Bundle)
with the target bundle. The only exception is the current video quality selection. The video quality will be stored as the initial quality in the bundle if adaptive bitrate switching is turned off and the quality was selected manually. In that case, adaptive bitrate switching will be turned off when the bundle is used to re-open content.- Parameters:
targetBundle
- the target bundle- Returns:
- True if the state was saved successfully
-
getContext
@NonNull public Context getContext()
- Returns:
- the context associated with this controller
-
getPlayerListeners
@NonNull public PlayerListeners getPlayerListeners()
- Returns:
- the player listeners
-
setSurface
public void setSurface(@Nullable Surface surface)
Set theSurface
that will be used to render video. Note that you usually do not need to call this method explicitly unless you are implementing your ownIPlayerView
. You need to call this method when the actual surface is created or destroyed (passnull
in that case). Usually you will need to add a listener to the surface provider, i.e.SurfaceView
, to be informed about state changes of the underlying surface.- Parameters:
surface
- The surface instance or null if the surface was destroyed
-
isSupportedAudioCodec
public static boolean isSupportedAudioCodec(String codec)
-
registerDrmSession
public void registerDrmSession(@NonNull DrmLicenseManager drmSessionManager)
INTERNAL: Register a drm session manager that is in use with this controller- Parameters:
drmSessionManager
- The drm session manager
-
getLiveEdgeUs
public long getLiveEdgeUs()
Returns the live edge time in microseconds, orC.TIME_UNSET
if unknown or not applicable. Same asgetLiveEdgeUs()
(boolean)} with true param.- Returns:
- the live edge in microseconds.
-
getLiveEdgeUs
public long getLiveEdgeUs(boolean applyOffset)
Returns the live edge time in microseconds, orC.TIME_UNSET
if unknown or not applicable.- Parameters:
applyOffset
- whether the currently set live edge latency (getLiveEdgeLatency()
should be taken into account or not.- Returns:
- the live edge in microseconds.
-
setComponentView
public void setComponentView(@IdRes int viewId, View view)
Set a specific component View.This method allows to inject Views for some PlayerControllerPlugins to use.
The PlayerControllerPlugins require a specific View to be set. If you are already using a
PlayerView
, then the correspondingPlayerViewPlugins
will take care of creating and adding these Views.If you opt not to use a PlayerView, you should add through this method the Views you want to provide the
PlayerControllerPlugins
with.In case a PlayerControllerPlugin cannot find the expected View it won't create on its own, and won't be able to function properly.
- Parameters:
viewId
- the viewId which links to the View. This can be usually be found as a constant in thePlayerPlugin
class which provides the specific View.view
- the instance of the specific View to add.- Since:
- 4.2.2
- See Also:
getComponentView(int)
-
unsetComponentView
public void unsetComponentView(@IdRes int viewId)
Remove the View linked to the provided view id- Parameters:
viewId
- the view id for the View to remove.- Since:
- 4.2.2
-
unsetComponentViews
public void unsetComponentViews()
Removes all the Component Views- Since:
- 4.2.2
-
scanComponentViews
public void scanComponentViews(@NonNull ViewGroup container)
Scans the given ViewGroup for specific PlayerControllerPlugin Views.Each
PlayerControllerPlugin
will be given the chance to search for its Views in the provided container.The Views can be at any hierarchy level, since they're looked for through the
View.findViewById(int)
method.The Views *have* to have as
id
the expected id, usually found as a constant in thePlayerPlugin
class which provides the specific View.- Parameters:
container
- the ViewGroup in which to look for specific Plugin Views- Since:
- 4.2.2
-
getComponentView
@Nullable public View getComponentView(@IdRes int viewId)
Returns a View previously set throughsetComponentView(int, View)
and indexed with a view id.The component Views returned by this method are the ones that will be used by their respective plugins.
- Parameters:
viewId
- the view id which identifies this View- Returns:
- the View linked to the provided viewId
- Since:
- 4.2.2
-
queryKeyStatus
@Nullable public Map<String,String> queryKeyStatus(@NonNull TrackRendererPlugin.Type trackType)
Queries the Key Status for the currently active session. Internally, this queries the platform'sMediaDrm
. The status is in the form of {name, value} pairs. Since DRM license policies vary by vendor, the specific status field names are determined by each DRM vendor.- Parameters:
trackType
- the track type for which to query the Key status. One ofTrackRendererPlugin.Type.Audio
,TrackRendererPlugin.Type.Video
orTrackRendererPlugin.Type.Other
. Other represents both audio and video; it applies when using the same DrmSessionManager to handle both licenses.- Returns:
- a Map of {name, value} pairs with the status of the currently loaded session, or null if no session is loaded, or the provided trackType does not match with the available DrmSessionManagers.
-
queryKeyStatus
public Map<String,String> queryKeyStatus()
Queries the Key Status for the currently loaded session. Internally, this queries the platform'sMediaDrm
. The status is in the form of {name, value} pairs. Since DRM license policies vary by vendor, the specific status field names are determined by each DRM vendor. This method will return the key status for a track with the following priority:TrackRendererPlugin.Type.Other
(both Audio and Video)TrackRendererPlugin.Type.Video
TrackRendererPlugin.Type.Audio
- Returns:
- a Map of {name, value} pairs with the status of the currently loaded session, or null if no session is loaded.
-
getLicenseRemainingDurationSec
public long getLicenseRemainingDurationSec(@NonNull TrackRendererPlugin.Type trackType)
Returns the remaining license duration for the current DRM session. In seconds. ReturnsC.TIME_UNSET
if unknown or no DRM session is currently open. If the license has no play duration and no expiration,Long.MAX_VALUE
will be returned.- Parameters:
trackType
- the track type for which to query the Key status. One ofTrackRendererPlugin.Type.Audio
,TrackRendererPlugin.Type.Video
orTrackRendererPlugin.Type.Other
. Other represents both audio and video; it applies when using the same DrmSessionManager to handle both licenses.- Returns:
- the remaining license duration in seconds, or C.TIME_UNSET.
-
getLicenseRemainingDurationSec
public long getLicenseRemainingDurationSec()
Returns the remaining license duration for the current DRM session. In seconds. ReturnsC.TIME_UNSET
if unknown or no DRM session is currently open. If the license has no play duration and no expiration,Long.MAX_VALUE
will be returned. This method will return the remaining license duration for a track with the following priority:TrackRendererPlugin.Type.Other
(both Audio and Video)TrackRendererPlugin.Type.Video
TrackRendererPlugin.Type.Audio
- Returns:
- the remaining license duration in seconds, or C.TIME_UNSET.
-
disableAudioFocus
public void disableAudioFocus()
Disables the audio focus for the stream regardless of thePlayerConfig.audioAttributes
-
resetAudioFocus
public void resetAudioFocus()
Resets the audio focus for the stream according to thePlayerConfig.audioAttributes
-
setPlayerView
public void setPlayerView(@Nullable IPlayerView playerView)
Sets theIPlayerView
instance that is used to provide the surface and render the video. Note that you usually do not need to call this method explicitly unless you are implementing your ownIPlayerView
. There is not need to call this method if you are using the defaultPlayerView
implementation.- Parameters:
playerView
- the player view
-
getPlayerView
@Nullable public IPlayerView getPlayerView()
- Returns:
- Returns the current view that is associated with this controller or null.
-
setAudioFocusCallback
public void setAudioFocusCallback(@Nullable com.google.android.exoplayer2.AudioFocusCallback audioFocusCallback)
Sets theAudioFocusCallback
. It will be called when audio focus is lost. It overrides the default behaviour, which is pausing the player.- Parameters:
audioFocusCallback
- the callback
-
movePlayerListeners
public void movePlayerListeners(@Nullable PlayerController playerController)
Migrates all the listeners from this PlayerController to the given one. Typical usage of this method is in an implementation ofMultiControllerPlaylist.PlaylistListener.onItemChange(PlayerConfig, PlayerController, PlayerController)
.- Parameters:
playerController
- The controller to which the listeners will be moved
-
createContentMediaSource
@NonNull public com.google.android.exoplayer2.source.MediaSource createContentMediaSource(@NonNull PlayerConfig playerConfig, @NonNull PlayerPlugin playerPlugin)
Creates a MediaSource for just one PlayerConfig. The resultin MediaSource will be wrapped by aClippingMediaSource
if needed.- Parameters:
playerConfig
- the config from which to create the MediaSourceplayerPlugin
- thePlayerPlugin
that will create the MediaSource- Returns:
- the MediaSource
-
getBitrateEstimate
public long getBitrateEstimate()
Returns the estimated bandwidth in bits/sec.- Returns:
- The estimated bandwidth
-
waitForMessages
public boolean waitForMessages()
Queues a message to an arbitrary target and blocks until its delivered.- Returns:
- True if the message was delivered
-
-