Class 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 the PlayerView implementation and its PlayerView.getPlayerController() method to get the controller instance for the current view.

    You can add PlayerListener 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
    • 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)
        Parameters:
        listener - the listener
      • removePlayerListener

        public void removePlayerListener​(@NonNull
                                         PlayerListener listener)
        Remove a registered PlayerListener
        Parameters:
        listener - the listener
      • removeDrmEventListener

        public void removeDrmEventListener​(@NonNull
                                           DrmEventListener listener)
        Remove a registered DrmEventListener
        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
      • addTimelineChangedListener

        public void addTimelineChangedListener​(TimelineChangedListener listener)
        Adds a listener to receive updates on Timeline updates
        Parameters:
        listener - the listener
      • addPeriodChangedListener

        public void addPeriodChangedListener​(PeriodChangedListener listener)
        Adds a listener to receive updates on Timeline.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 calling open(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
      • getDataSourceFactory

        @NonNull
        public DataSourceFactory getDataSourceFactory()
        Provides access to the DataSourceFactory. 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 the DataSourceFactory 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 set SSLSocketFactory
        Returns:
        SSLSocketFactory or null when unknown
      • setSSLSocketFactory

        public void setSSLSocketFactory​(@Nullable
                                        SSLSocketFactory sslSocketFactory)
        Set custom SSLSocketFactory to be used in DRM and content requests. Takes precedence over PlayerSDK.SSL_KEY_STORE
        Parameters:
        sslSocketFactory - SSLSocketFactory
      • getBandwidthMeterWrapper

        @NonNull
        public BandwidthMeterWrapper getBandwidthMeterWrapper()
        The bandwidth meter wrapper
        Returns:
        bandwidthMeter
      • setExternalSourceSelector

        public void setExternalSourceSelector​(@Nullable
                                              ExternalSourceSelector externalSourceSelector)
        Set the ExternalSourceSelector that will be used during CDN fallback Set null to disable the CDN fallback
        Parameters:
        externalSourceSelector - The CDN selector
      • setInternalSourceSelectorFactory

        public void setInternalSourceSelectorFactory​(@Nullable
                                                     com.google.android.exoplayer2.upstream.InternalSourceSelector.Factory sourceSelectorFactory)
        Set the InternalSourceSelector.Factory that will be used during CDN fallback Set null to use the default PlayerSDK.DEFAULT_INTERNAL_SOURCE_SELECTOR_FACTORY
        Parameters:
        sourceSelectorFactory - The InternalSourceSelector.Factory
      • setPeriodInfoProvider

        public void setPeriodInfoProvider​(@Nullable
                                          PeriodInfoProvider periodInfoProvider)
        Set the PeriodInfoProvider that will be used to get additional information for the played period.

        Use it to enable period-based ads handling.

        Parameters:
        periodInfoProvider - The PeriodInfoProvider.PeriodInfo provider
      • 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 the PlayerService 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 streams isLive() the current position since epoch can be obtained as getLiveStartTime() + 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 what getPosition() 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 microseconds
        sendToAnalytics - 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 which TrickplayConfiguration to use. Note that in order to apply this configuration you should also enable it.
        Parameters:
        trickplayConfiguration - the TrickplayConfiguration to set
        Returns:
        true if the provided TrickplayConfiguration has actually been applied. The configuration won't be applied if it's invalid. eg. Negative speed and decoder mode.
      • setHlsKeyCache

        public void setHlsKeyCache​(@Nullable
                                   HlsClearKeyCache hlsKeyCache)
        Sets the HlsClearKeyCache used for HLS Clearkey requests. Must be set before the open(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
      • 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 qualities setVideoQuality(VideoTrackQuality) before changing the playback speed.

        Parameters:
        speed - The playback speed
      • 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 the Intent that's sent to open(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 pass null 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 example SubtitlesStyle.hasForegroundColor and the other hasXXX flags on the style).

        This method can be used for example, to set the user specified accessibility settings required for FCC compliance.

        You can pass null 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 pass null 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 call open(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 with AudioTrack.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 call open(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 pass null to disable video playback.

        Note that this is not the same as setVideoQuality(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 pass null to disable video playback.

        Note that this is not the same as setVideoQuality(VideoTrackQuality) and in most cases you will only have one video track with multiple qualities.
        Parameters:
        track - the video track
        quality - the quality
      • getTimeline

        @NonNull
        public Timeline getTimeline()
        Returns the current Timeline. 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
      • 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 existing initial track selection will be lost.
        Parameters:
        videoQuality - the quality
      • getAbrConfiguration

        @NonNull
        public AbrConfiguration getAbrConfiguration()
        Returns the current ABR configuration
        Returns:
        The ABR configuration
      • getVideoSizeFilter

        @NonNull
        public Point getVideoSizeFilter()
        Returns the current video size filter
        Returns:
        The current video size filter
      • 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, otherwise null
        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.

        Use isLive() 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 or C.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
      • setAnalyticsSession

        public void setAnalyticsSession​(@Nullable
                                        AnalyticsSession analyticsSession)
        Set an already existing AnalyticsSession. This should be called before open(Bundle). Setting null will detach 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 the getAnalyticsSession() 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 using open(PlayerConfig) and no Bundle 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
                         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 use setAnalyticsMetaData(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 a playerView, 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 call open(Bundle) or open(PlayerConfig) to restart playback.
      • getKeyStore

        @Nullable
        public static KeyStore getKeyStore()
        Returns the KeyStore that will be used to store offline IDs or null if no store is configured. This is the same as PlayerSDK.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
      • 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 call open(Bundle) to have an effect on the playback.
        Parameters:
        liveConfiguration - The live configuration
      • 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 given Bundle which is the saved state obtained with saveState(Bundle)
        Parameters:
        bundle - The Bundle to open the PlayerController 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 using open(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 the Surface that will be used to render video. Note that you usually do not need to call this method explicitly unless you are implementing your own IPlayerView.

        You need to call this method when the actual surface is created or destroyed (pass null 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, or C.TIME_UNSET if unknown or not applicable. Same as getLiveEdgeUs() (boolean)} with true param.
        Returns:
        the live edge in microseconds.
      • getLiveEdgeUs

        public long getLiveEdgeUs​(boolean applyOffset)
        Returns the live edge time in microseconds, or C.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 corresponding PlayerViewPlugins 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 the PlayerPlugin 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 idthe expected id, usually found as a constant in the PlayerPlugin 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 through setComponentView(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's MediaDrm. 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 of TrackRendererPlugin.Type.Audio, TrackRendererPlugin.Type.Video or TrackRendererPlugin.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's MediaDrm. 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:

        1. TrackRendererPlugin.Type.Other (both Audio and Video)
        2. TrackRendererPlugin.Type.Video
        3. 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. Returns C.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 of TrackRendererPlugin.Type.Audio, TrackRendererPlugin.Type.Video or TrackRendererPlugin.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. Returns C.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:

        1. TrackRendererPlugin.Type.Other (both Audio and Video)
        2. TrackRendererPlugin.Type.Video
        3. 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 the PlayerConfig.audioAttributes
      • setPlayerView

        public void setPlayerView​(@Nullable
                                  IPlayerView playerView)
        Sets the IPlayerView 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 own IPlayerView. There is not need to call this method if you are using the default PlayerView 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 the AudioFocusCallback. It will be called when audio focus is lost. It overrides the default behaviour, which is pausing the player.
        Parameters:
        audioFocusCallback - the callback
      • 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 a ClippingMediaSource if needed.
        Parameters:
        playerConfig - the config from which to create the MediaSource
        playerPlugin - the PlayerPlugin 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