Class MediaPlayerPlayback

java.lang.Object
com.brightcove.player.event.AbstractComponent
com.brightcove.player.playback.MediaPlayerPlayback
All Implemented Interfaces:
Component, MediaPlayback<android.media.MediaPlayer>

@Emits(events={"bufferedUpdate","completed","didSetSource","didChangeList","didPlay","didInterruptContent","didResumeContent","didPause","didStop","didSeekTo","didSelectSource","error","play","prebufferNextVideo","progress","selectSource","setSource","setVideo","sourceNotPlayable","sourceNotPlayable","videoSizeKnown","videoDurationChanged","willChangeVideo"}) @ListensFor(events={"bufferedUpdate","completed","didPlay","didSetSource","on360FrameAvailable","play","pause","prebufferNextVideo","readyToPlay","stop","seekTo","setSource","setVolume","videoDurationChanged","willChangeVideo","willInterruptContent","willResumeContent"}) @RestrictTo(LIBRARY) public class MediaPlayerPlayback extends AbstractComponent implements MediaPlayback<android.media.MediaPlayer>
  • Field Details

    • progressInterval

      protected int progressInterval
    • updater

      protected ScheduledFuture<?> updater
    • nextVideo

      protected Video nextVideo
    • nextSource

      protected Source nextSource
    • isPlayingForTesting

      public boolean isPlayingForTesting
    • onPreparedListener

      public final android.media.MediaPlayer.OnPreparedListener onPreparedListener
    • onErrorListener

      public final android.media.MediaPlayer.OnErrorListener onErrorListener
    • onBufferingUpdateListener

      public final android.media.MediaPlayer.OnBufferingUpdateListener onBufferingUpdateListener
    • onCompletionListener

      public final android.media.MediaPlayer.OnCompletionListener onCompletionListener
    • onSeekCompleteListener

      public final android.media.MediaPlayer.OnSeekCompleteListener onSeekCompleteListener
    • onInfoListener

      public final android.media.MediaPlayer.OnInfoListener onInfoListener
  • Constructor Details

    • MediaPlayerPlayback

      public MediaPlayerPlayback(RenderView renderView, android.content.Context context, EventEmitter eventEmitter)
  • Method Details

    • 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<android.media.MediaPlayer>
      Parameters:
      video - reference to the video to be prepared for the playback.
      source - reference to the source to played if any.
    • openCurrentVideoSource

      public void openCurrentVideoSource()
      Prepares the player to play the current video source.
      Specified by:
      openCurrentVideoSource in interface MediaPlayback<android.media.MediaPlayer>
    • getSourceController

      public DefaultSourceSelectionController getSourceController()
      Description copied from interface: MediaPlayback
      The source selector which uses a delegate to select sources.
      Specified by:
      getSourceController in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      A source controller
    • startUpdater

      protected void startUpdater()
    • stopUpdater

      protected void stopUpdater()
    • destroyPlayer

      public void destroyPlayer()
      Destroys the current player and releases it from memory. This seems wasteful, but helps to mitigate working with the complex state machines that are the MediaPlayer and the SurfaceView
      Specified by:
      destroyPlayer in interface MediaPlayback<android.media.MediaPlayer>
      See Also:
      • MediaPlayer
      • SurfaceView
    • 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<android.media.MediaPlayer>
      Parameters:
      video - reference to the video, if any.
      source - reference to the video source, if any.
    • getPlayer

      public android.media.MediaPlayer getPlayer()
      Description copied from interface: MediaPlayback
      Get the player used for media playback.
      Specified by:
      getPlayer in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      The media player.
    • getCurrentVideo

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

      public Source getCurrentSource()
      Description copied from interface: MediaPlayback
      Get the current source for the Video.
      Specified by:
      getCurrentSource in interface MediaPlayback<android.media.MediaPlayer>
      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<android.media.MediaPlayer>
      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<android.media.MediaPlayer>
      Returns:
      the analytics component
    • 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<android.media.MediaPlayer>
      Parameters:
      rootIntent - The original Intent that was used to launch the task that is being removed.
    • getNotification

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

      public List<Video> getPlaylist()
      Description copied from interface: MediaPlayback
      Returns a immutable copy of the video list.
      Specified by:
      getPlaylist in interface MediaPlayback<android.media.MediaPlayer>
    • isPlaying

      public boolean isPlaying()
      Specified by:
      isPlaying in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      True if the player is currently playing.
    • hasDvr

      public boolean hasDvr()
      Indicates if Live with DVR is supported. Subclasses will override if live with DVR videos are supported.
      Specified by:
      hasDvr in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      TRUE iff live video with DVR capabilities is supported.
    • isLive

      public boolean isLive()
      Provides a default for handling live videos. Subclasses will override if live videos are supported.
      Specified by:
      isLive in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      TRUE iff live video is supported.
    • getLiveEdge

      public long getLiveEdge()
      Obtains the playhead position of the "live edge".
      Specified by:
      getLiveEdge in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      0. Subclasses should override to provide a value within three target durations of the maximum position.
    • isInLiveEdge

      public boolean isInLiveEdge()
      Checks the current playhead position with the live edge position and determines if it is in live edge.
      Specified by:
      isInLiveEdge in interface MediaPlayback<android.media.MediaPlayer>
      Returns:
      true if in live edge.
    • getCurrentPosition

      public long getCurrentPosition()
      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<android.media.MediaPlayer>
      Returns:
      the current playhead position.
    • 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<android.media.MediaPlayer>
      Parameters:
      progressInterval - the PROGRESS interval in milliseconds
    • 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<android.media.MediaPlayer>
    • add

      public void add(int index, Video video)
      Description copied from interface: MediaPlayback
      Adds the video to the video list at the specified index.
      Specified by:
      add in interface MediaPlayback<android.media.MediaPlayer>
    • addAll

      public void addAll(Collection<Video> videos)
      Description copied from interface: MediaPlayback
      Add all videos in the collection to the end of the list.
      Specified by:
      addAll in interface MediaPlayback<android.media.MediaPlayer>
      Parameters:
      videos - The videos to append.
    • addAll

      public void addAll(int index, Collection<Video> videos)
      Description copied from interface: MediaPlayback
      Inserts all videos in the collection at the specified index.
      Specified by:
      addAll in interface MediaPlayback<android.media.MediaPlayer>
    • setVideoPath

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

      public Video setVideoPath(String videoPath, Map<String,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<android.media.MediaPlayer>
      Parameters:
      videoPath - HTTP path to the video
      languageCodeCaptionsMap - A map of language code to caption urls.
    • 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<android.media.MediaPlayer>
    • getCurrentIndex

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

      public void setCurrentIndex(int index)
      Description copied from interface: MediaPlayback
      Sets the current video to the specified index.
      Specified by:
      setCurrentIndex in interface MediaPlayback<android.media.MediaPlayer>
    • remove

      public void remove(int index) throws IndexOutOfBoundsException
      Description copied from interface: MediaPlayback
      Removes the video at the specified index.
      Specified by:
      remove in interface MediaPlayback<android.media.MediaPlayer>
      Throws:
      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<android.media.MediaPlayer>
    • getBufferPercentage

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

      public float getVolume()
      Specified by:
      getVolume in interface MediaPlayback<android.media.MediaPlayer>
    • isSourceSet

      public boolean isSourceSet()
      Description copied from interface: MediaPlayback
      Returns if a source has been set
      Specified by:
      isSourceSet in interface MediaPlayback<android.media.MediaPlayer>
    • 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<android.media.MediaPlayer>
    • emitErrorEvent

      public void emitErrorEvent(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<android.media.MediaPlayer>
    • emitErrorEvent

      public void emitErrorEvent(String message, 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<android.media.MediaPlayer>