Class ExoMediaPlayback

  • All Implemented Interfaces:
    Component, MediaPlayback<com.google.android.exoplayer2.ExoPlayer>

    @Emits(events={"bufferedUpdate","completed","didInterruptContent","didPause","didPlay","didResumeContent","didSeekTo","didSetSource","didStop","error","pause","play","progress","sourceNotPlayable","stop","videoDurationChanged","willChangeVideo","addAnalyticsBaseParams","analyticsVideoEngagement","audioTracks","bufferingCompleted","bufferingStarted","caption","captionsLanguages","toggleClosedCaptions","seekToIncorrectTargetValue","didChangeList","setVideo","setSource","selectSource","didSelectSource","didSetVideo","sourceNotFound","setVideoStill","volumeChange","renditionChanged"})
    @ListensFor(events={"pause","play","seekTo","setSource","stop","willInterruptContent","willResumeContent","didSetAnalyticsBaseParams","setVolume","didSetVideo","didPlay","didSeekTo","resumeFromCastSession","selectAudioTrack","selectClosedCaptionTrack","on360FrameAvailable"})
    @RestrictTo(LIBRARY)
    public class ExoMediaPlayback
    extends AbstractComponent
    implements MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
    This class extends the VideoDisplayComponent to add support for the ExoPlayer.

    See: https://github.com/google/ExoPlayer

    See Also:
    VideoDisplayComponent
    • Field Detail

      • resourceBundle

        public static java.util.ResourceBundle resourceBundle
      • progressInterval

        protected int progressInterval
      • mainHandler

        protected final android.os.Handler mainHandler
      • playheadPosition

        protected long playheadPosition
      • seekPosition

        protected long seekPosition
      • context

        protected final android.content.Context context
      • fromSeekPosition

        protected long fromSeekPosition
      • drmEventListener

        protected final com.google.android.exoplayer2.drm.DrmSessionEventListener drmEventListener
      • adaptiveMediaSourceEventListener

        protected final com.google.android.exoplayer2.source.MediaSourceEventListener adaptiveMediaSourceEventListener
    • Constructor Detail

      • ExoMediaPlayback

        public ExoMediaPlayback​(android.content.Context context,
                                EventEmitter eventEmitter)
    • Method Detail

      • onTaskRemoved

        public void onTaskRemoved​(android.content.Intent rootIntent)
        Description copied from interface: MediaPlayback
        This is called when the MediaPlaybackService is currently running and the user has removed a task that comes from the service's application.
        Specified by:
        onTaskRemoved in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        rootIntent - The original Intent that was used to launch the task that is being removed.
      • getNotification

        @Nullable
        public BrightcoveNotification getNotification()
        Description copied from interface: MediaPlayback
        Get the object which handles showing an on-going player notification.
        Specified by:
        getNotification in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        An object to configure the on-going playback notification.
      • getPlaylist

        public java.util.List<Video> getPlaylist()
        Description copied from interface: MediaPlayback
        Returns a immutable copy of the video list.
        Specified by:
        getPlaylist in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • isPlaying

        public boolean isPlaying()
        Specified by:
        isPlaying in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        True if the player is currently playing.
      • setVideoPath

        public Video setVideoPath​(java.lang.String path)
        Description copied from interface: MediaPlayback
        Replaces player content with the video at the specified path.
        Specified by:
        setVideoPath in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        path - HTTP path to a video
        Returns:
        The created Video object.
      • setVideoPath

        public Video setVideoPath​(java.lang.String videoPath,
                                  java.util.Map<java.lang.String,​java.lang.String> languageCodeCaptionsMap)
        Description copied from interface: MediaPlayback
        Replace player content with the video and captions at the specified paths.
        Specified by:
        setVideoPath in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        videoPath - HTTP path to the video
        languageCodeCaptionsMap - A map of language code to caption urls.
      • add

        public void add​(Video video)
        Description copied from interface: MediaPlayback
        Adds the video to the end of the video list.
        Specified by:
        add in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • add

        public void add​(int index,
                        Video video)
                 throws java.lang.IndexOutOfBoundsException
        Description copied from interface: MediaPlayback
        Adds the video to the video list at the specified index.
        Specified by:
        add in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Throws:
        java.lang.IndexOutOfBoundsException - when index < 0 or index is larger than the size of the video list.
      • addAll

        public void addAll​(java.util.Collection<Video> newVideos)
        Description copied from interface: MediaPlayback
        Add all videos in the collection to the end of the list.
        Specified by:
        addAll in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        newVideos - The videos to append.
      • addAll

        public void addAll​(int index,
                           java.util.Collection<Video> newVideos)
                    throws java.lang.IndexOutOfBoundsException
        Description copied from interface: MediaPlayback
        Inserts all videos in the collection at the specified index.
        Specified by:
        addAll in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Throws:
        java.lang.IndexOutOfBoundsException - when index < 0 or index is larger than the size of the video list.
      • getVideoAt

        public Video getVideoAt​(int index)
        Description copied from interface: MediaPlayback
        Gets a video from the video list at the specified index
        Specified by:
        getVideoAt in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • getCurrentIndex

        public int getCurrentIndex()
        Description copied from interface: MediaPlayback
        Gets the index from the current video
        Specified by:
        getCurrentIndex in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        The index of the current video or -1 if there are none.
      • setCurrentIndex

        public void setCurrentIndex​(int index)
                             throws java.lang.IndexOutOfBoundsException
        Description copied from interface: MediaPlayback
        Sets the current video to the specified index.
        Specified by:
        setCurrentIndex in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Throws:
        java.lang.IndexOutOfBoundsException - when index < 0 or index is larger than the size of the video list.
      • remove

        public void remove​(int index)
                    throws java.lang.IndexOutOfBoundsException
        Description copied from interface: MediaPlayback
        Removes the video at the specified index.
        Specified by:
        remove in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Throws:
        java.lang.IndexOutOfBoundsException - when index < 0 or index is larger than the size of the video list.
      • clear

        public void clear()
        Description copied from interface: MediaPlayback
        Removes all videos from the list.
        Specified by:
        clear in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • getBufferPercentage

        public int getBufferPercentage()
        Description copied from interface: MediaPlayback
        Returns the buffer percentage
        Specified by:
        getBufferPercentage in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • getVolume

        public float getVolume()
        Specified by:
        getVolume in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • isSourceSet

        public boolean isSourceSet()
        Description copied from interface: MediaPlayback
        Returns if a source has been set
        Specified by:
        isSourceSet in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • getTrackSelector

        @Nullable
        public com.google.android.exoplayer2.trackselection.DefaultTrackSelector getTrackSelector()
        Gets the DefaultTrackSelector object.
        Returns:
        the track selector
        See Also:
        DefaultTrackSelector
      • getTrackSelectorHelper

        @Nullable
        public TrackSelectorHelper getTrackSelectorHelper()
        Gets the TrackSelectorHelper object.
        Returns:
        the track selector helper
        See Also:
        TrackSelectorHelper
      • setTrackSelector

        public void setTrackSelector​(@NonNull
                                     com.google.android.exoplayer2.trackselection.DefaultTrackSelector trackSelector)
      • setNotificationConfig

        public void setNotificationConfig​(PlaybackNotification.Config config)
        Configure the on-going notification.
        Parameters:
        config - The configuration to apply to the notification.
      • emitErrorEvent

        public void emitErrorEvent​(java.lang.String message)
        Description copied from interface: MediaPlayback
        Emits an error event with the message passed in the event's properties
        Specified by:
        emitErrorEvent in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • emitErrorEvent

        public void emitErrorEvent​(java.lang.String message,
                                   java.lang.Exception exception)
        Description copied from interface: MediaPlayback
        Emits an error event including the message passed and the exception in the properties
        Specified by:
        emitErrorEvent in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • setEventEmitter

        @RestrictTo(LIBRARY)
        public ExoMediaPlayback setEventEmitter​(EventEmitter eventEmitter)
        This is used to reset the EventEmitter when restoring the playback from the service.
        Parameters:
        eventEmitter - The new event emitter to set for this playback instance.
        Returns:
        This playback instance
      • initializeListeners

        protected void initializeListeners()
      • startUpdater

        protected void startUpdater()
      • stopUpdater

        protected void stopUpdater()
      • hasDvr

        public boolean hasDvr()
        Description copied from interface: MediaPlayback
        Indicates if the current stream is a live video with DVR.
        Specified by:
        hasDvr in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        TRUE iff live video with DVR capabilities is supported.
      • isLive

        public boolean isLive()
        Description copied from interface: MediaPlayback
        Indicates whether the current stream is a live video.
        Specified by:
        isLive in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        TRUE iff live video is supported.
      • isInLiveEdge

        public boolean isInLiveEdge()
        Description copied from interface: MediaPlayback
        Checks the current playhead position with the live edge position and determines if it is within range of the live edge.
        Specified by:
        isInLiveEdge in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        true if in live edge.
      • getCurrentPosition

        public long getCurrentPosition()
        Description copied from interface: MediaPlayback
        Returns the current playhead position of the underlying video player.

        If the player has not been set or initialized, Constants.TIME_UNSET will returned.

        Specified by:
        getCurrentPosition in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        the current playhead position.
      • getPlayer

        public com.google.android.exoplayer2.ExoPlayer getPlayer()
        Description copied from interface: MediaPlayback
        Get the player used for media playback.
        Specified by:
        getPlayer in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        The media player.
      • getLiveEdge

        public long getLiveEdge()
        Compute the "live edge" as a long datatype, the largest position not within three target durations of the duration (per the HLS spec).
        Specified by:
        getLiveEdge in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        -1 if the video is not live. Otherwise the largest position that is three target durations away from the duration.
      • getPlayerState

        public int getPlayerState()
        Returns the ExoPlayer state if available, or -1 if the player is null.
        Returns:
        the player state
        See Also:
        Player.getPlaybackState()
      • setVideoSource

        public void setVideoSource​(@Nullable
                                   Video video,
                                   @Nullable
                                   Source source)
        Sets the video source that will be used for playback.
        Specified by:
        setVideoSource in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        video - reference to the video, if any.
        source - reference to the video source, if any.
      • setProgressInterval

        public void setProgressInterval​(int progressInterval)
        Sets the the interval in milliseconds at which to fire PROGRESS events during playback. The default is 500ms.
        Specified by:
        setProgressInterval in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        progressInterval - the PROGRESS interval in milliseconds
      • getCurrentVideo

        @Nullable
        public Video getCurrentVideo()
        Description copied from interface: MediaPlayback
        Get the currently playing video.
        Specified by:
        getCurrentVideo in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        The current media object.
      • getCurrentSource

        @Nullable
        public Source getCurrentSource()
        Description copied from interface: MediaPlayback
        Get the current source for the Video.
        Specified by:
        getCurrentSource in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        The source used for playback.
      • isPlayingAudioOnly

        public boolean isPlayingAudioOnly()
        Description copied from interface: MediaPlayback
        Check if the player is currently playing and the media is audio-only.
        Specified by:
        isPlayingAudioOnly in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        True if the player is currently playing audio-only media; false otherwise.
      • getAnalytics

        public Analytics getAnalytics()
        Description copied from interface: MediaPlayback
        Returns the analytics component, the part of the player that monitors and tracks video playback and engagement.
        Specified by:
        getAnalytics in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Returns:
        the analytics component
      • openCurrentVideoSource

        public void openCurrentVideoSource()
        Description copied from interface: MediaPlayback
        Prepares the player to play the current video source.
        Specified by:
        openCurrentVideoSource in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • openVideo

        public void openVideo​(@NonNull
                              Video video,
                              @Nullable
                              Source source)
        Description copied from interface: MediaPlayback
        Creates, configures, and prepares a new instance of MediaPlayback
        Specified by:
        openVideo in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        video - reference to the video to be prepared for the playback.
        source - reference to the source to played if any.
      • getAllowHlsChunklessPreparation

        public boolean getAllowHlsChunklessPreparation()
        Returns:
        Whether to allow HLS chunkless preparation in ExoPlayer
      • setAllowHlsChunklessPreparation

        public void setAllowHlsChunklessPreparation​(boolean allowHlsChunklessPreparation)
        The value of this field in the HlsMediaSource defaults to true in ExoPlayer 2.17.0 Override it here to false if your HLS delivery includes 608/708 captions
      • isCurrentVideo360Mode

        public boolean isCurrentVideo360Mode()
        Description copied from interface: MediaPlayback
        Returns true if the video is a 360 video otherwise returns false
        Specified by:
        isCurrentVideo360Mode in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
      • destroyPlayer

        public void destroyPlayer()
        Description copied from interface: MediaPlayback
        Destroys the current player and releases it from memory. This helps to manage working with the complex state machines that are the MediaPlayer and the SurfaceView
        Specified by:
        destroyPlayer in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        See Also:
        MediaPlayer, SurfaceView
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getDefaultRenderersFactory

        @Nullable
        public com.google.android.exoplayer2.DefaultRenderersFactory getDefaultRenderersFactory()
        Gets the DefaultRenderersFactory object.
        Returns:
        the DefaultRenderersFactory
        See Also:
        DefaultRenderersFactory
      • setDefaultRenderersFactory

        public void setDefaultRenderersFactory​(@NonNull
                                               com.google.android.exoplayer2.DefaultRenderersFactory defaultRenderersFactory)
      • play

        public void play​(long position)
        Convenience method for easily starting the exoplayer.
      • pause

        public void pause()
        Convenience method for easily pausing the exoplayer.
      • onHandlePlayPauseAction

        protected void onHandlePlayPauseAction​(int state)
        Handle internal state and events for play/pause.
      • getPlaybackLooper

        public android.os.Looper getPlaybackLooper()
      • getMainHandler

        public android.os.Handler getMainHandler()
      • getVideoFormat

        public com.google.android.exoplayer2.Format getVideoFormat()
      • getAudioFormat

        public com.google.android.exoplayer2.Format getAudioFormat()
      • getPeakBitrate

        public int getPeakBitrate()
        Return the peak bitrate.
      • setPeakBitrate

        public void setPeakBitrate​(int peakBitrate)
        Sets the peak bitrate. Set 0 to set the default bitrate.
        Parameters:
        peakBitrate - the peak bitrate
      • replace

        public void replace​(int index,
                            Video video)
        Description copied from interface: MediaPlayback
        Removes and replaces the video at the specified index.
        Specified by:
        replace in interface MediaPlayback<com.google.android.exoplayer2.ExoPlayer>
        Parameters:
        index - The index to replace a media item.
        video - The video to replace
      • getBandwidthMeter

        public com.google.android.exoplayer2.upstream.BandwidthMeter getBandwidthMeter()
        Returns the current bandwidth meter. If null, a default bandwidth meter will be used.
      • setBandwidthMeter

        public void setBandwidthMeter​(com.google.android.exoplayer2.upstream.BandwidthMeter bandwidthMeter)
        Sets the current bandwidth meter.
      • getDataSourceFactory

        @NonNull
        public com.google.android.exoplayer2.upstream.HttpDataSource.Factory getDataSourceFactory()
        Returns the current HttpDataSource.Factory, which is used when creating the MediaSource.
      • setDataSourceFactory

        public void setDataSourceFactory​(@NonNull
                                         com.google.android.exoplayer2.upstream.HttpDataSource.Factory httpDataSourceFactory)
        Sets the HttpDataSource.Factory, which is used when creating the MediaSource. WARNING: When creating a customized HttpDataSource.Factory, you must make sure to use the default user agent C.HTTP_USER_AGENT to avoid losing Brightcove Analytics and Delivery Rules support.
        Parameters:
        httpDataSourceFactory - the http data source factory
      • getMinBufferDurationToSwitchUp

        @Deprecated
        public long getMinBufferDurationToSwitchUp()
        Deprecated.
        It is not longer used for ExoPlayer v2.
        Returns the minimum duration of media that needs to be buffered for a switch to a higher quality variant to be considered.
      • setMinBufferDurationToSwitchUp

        @Deprecated
        public void setMinBufferDurationToSwitchUp​(long minBufferDurationToSwitchUp)
        Deprecated.
        It is not longer used for ExoPlayer v2.
        Sets the minimum duration of media that needs to be buffered for a switch to a higher quality variant to be considered.
      • getMaxBufferDurationToSwitchDown

        @Deprecated
        public long getMaxBufferDurationToSwitchDown()
        Deprecated.
        It is not longer used for ExoPlayer v2.
        Returns the maximum duration of media that needs to be buffered for a switch to a lower quality variant to be considered.
      • setMaxBufferDurationToSwitchDown

        @Deprecated
        public void setMaxBufferDurationToSwitchDown​(long maxBufferDurationToSwitchDown)
        Deprecated.
        It is not longer used for ExoPlayer v2.
        Sets the maximum duration of media that needs to be buffered for a switch to a lower quality variant to be considered.
      • getMinBufferMs

        @Deprecated
        public int getMinBufferMs()
        Deprecated.
        It is not longer used for ExoPlayer v2.
        Returns the minimum duration of data that must be buffered for playback to start or resume following a user action such as a seek.
      • setMinBufferMs

        @Deprecated
        public void setMinBufferMs​(int minBufferMs)
        Deprecated.
        It is not longer used for ExoPlayer v2.
        Sets the minimum duration of data that must be buffered for playback to start or resume following a user action such as a seek.
      • getMinRebufferMs

        @Deprecated
        public int getMinRebufferMs()
        Deprecated.
        It is not longer used for ExoPlayer v2. Use Use getLoadControlConfig()
      • getLoadControlConfig

        public LoadControlConfig getLoadControlConfig()
        Gets the LoadControlConfig object.
        Returns:
        the load control config
      • setLoadControlConfig

        public void setLoadControlConfig​(@NonNull
                                         LoadControlConfig loadControlConfig)
        Sets the LoadControlConfig object.

        This object is used to create a LoadControl instance. The LoadControl is used when creating an instance of the ExoPlayer.

        Parameters:
        loadControlConfig - the load control config
      • buildDataSourceFactory

        protected com.google.android.exoplayer2.upstream.DataSource.Factory buildDataSourceFactory​(com.google.android.exoplayer2.upstream.HttpDataSource.Factory httpDatasourceFactory,
                                                                                                   boolean useBandwidthMeter)
        Returns a new DataSource factory.
        Parameters:
        httpDatasourceFactory - contains RequestProperties information (such as Video request headers)
        useBandwidthMeter - specifies whether the transfer operations must be tracked using the bandwidth meter.
        Returns:
        A new DataSource factory.
      • getVideoDisplayProperties

        public java.util.Map<java.lang.String,​java.lang.String> getVideoDisplayProperties()
      • setVideoDisplayProperties

        public void setVideoDisplayProperties​(java.util.Map<java.lang.String,​java.lang.String> videoDisplayProperties)