Package com.brightcove.player.playback
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>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MediaPlayerPlayback.OnSetSourceListener
protected class
MediaPlayerPlayback.OnWillChangeVideoListener
-
Field Summary
Fields Modifier and Type Field Description boolean
isPlayingForTesting
protected Source
nextSource
protected Video
nextVideo
android.media.MediaPlayer.OnBufferingUpdateListener
onBufferingUpdateListener
android.media.MediaPlayer.OnCompletionListener
onCompletionListener
android.media.MediaPlayer.OnErrorListener
onErrorListener
android.media.MediaPlayer.OnInfoListener
onInfoListener
android.media.MediaPlayer.OnPreparedListener
onPreparedListener
android.media.MediaPlayer.OnSeekCompleteListener
onSeekCompleteListener
protected int
progressInterval
protected java.util.concurrent.ScheduledFuture<?>
updater
-
Fields inherited from class com.brightcove.player.event.AbstractComponent
listenerTokens
-
-
Constructor Summary
Constructors Constructor Description MediaPlayerPlayback(RenderView renderView, android.content.Context context, EventEmitter eventEmitter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, Video video)
Adds the video to the video list at the specified index.void
add(Video video)
Adds the video to the end of the video list.void
addAll(int index, java.util.Collection<Video> videos)
Inserts all videos in the collection at the specified index.void
addAll(java.util.Collection<Video> videos)
Add all videos in the collection to the end of the list.void
clear()
Removes all videos from the list.void
destroyPlayer()
Destroys the current player and releases it from memory.void
emitErrorEvent(java.lang.String message)
Emits an error event with the message passed in the event's propertiesvoid
emitErrorEvent(java.lang.String message, java.lang.Exception exception)
Emits an error event including the message passed and the exception in the propertiesAnalytics
getAnalytics()
Returns the analytics component, the part of the player that monitors and tracks video playback and engagement.int
getBufferPercentage()
Returns the buffer percentageint
getCurrentIndex()
Gets the index from the current videolong
getCurrentPosition()
Returns the current playhead position of the underlying video player.Source
getCurrentSource()
Get the current source for theVideo
.Video
getCurrentVideo()
Get the currently playing video.long
getLiveEdge()
Obtains the playhead position of the "live edge".PlaybackNotification
getNotification()
Get the object which handles showing an on-going player notification.android.media.MediaPlayer
getPlayer()
Get the player used for media playback.java.util.List<Video>
getPlaylist()
Returns a immutable copy of the video list.DefaultSourceSelectionController
getSourceController()
The source selector which uses a delegate to select sources.Video
getVideoAt(int index)
Gets a video from the video list at the specified indexfloat
getVolume()
boolean
hasDvr()
Indicates if Live with DVR is supported.boolean
isCurrentVideo360Mode()
Returns true if the video is a 360 video otherwise returns falseboolean
isInLiveEdge()
Checks the current playhead position with the live edge position and determines if it is in live edge.boolean
isLive()
Provides a default for handling live videos.boolean
isPlaying()
boolean
isPlayingAudioOnly()
Check if the player is currently playing and the media is audio-only.boolean
isSourceSet()
Returns if a source has been setvoid
onTaskRemoved(android.content.Intent rootIntent)
This is called when theMediaPlaybackService
is currently running and the user has removed a task that comes from the service's application.void
openCurrentVideoSource()
Prepares the player to play the current video source.void
openVideo(Video video, Source source)
Creates, configures, and prepares a new instance of MediaPlaybackvoid
remove(int index)
Removes the video at the specified index.void
setCurrentIndex(int index)
Sets the current video to the specified index.void
setProgressInterval(int progressInterval)
Sets the the interval in milliseconds at which to fire PROGRESS events during playback.Video
setVideoPath(java.lang.String path)
Replaces player content with the video at the specified path.Video
setVideoPath(java.lang.String videoPath, java.util.Map<java.lang.String,java.lang.String> languageCodeCaptionsMap)
Replace player content with the video and captions at the specified paths.void
setVideoSource(Video video, Source source)
Sets the video source that will be used for playback.protected void
startUpdater()
protected void
stopUpdater()
-
Methods inherited from class com.brightcove.player.event.AbstractComponent
addListener, addOnceListener, getEventEmitter, removeListener, removeListeners
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.brightcove.player.playback.MediaPlayback
replace
-
-
-
-
Field Detail
-
progressInterval
protected int progressInterval
-
updater
protected java.util.concurrent.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 Detail
-
MediaPlayerPlayback
public MediaPlayerPlayback(RenderView renderView, android.content.Context context, EventEmitter eventEmitter)
-
-
Method Detail
-
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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<android.media.MediaPlayer>
- Returns:
- The current media object.
-
getCurrentSource
public Source getCurrentSource()
Description copied from interface:MediaPlayback
Get the current source for theVideo
.- Specified by:
getCurrentSource
in interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<android.media.MediaPlayer>
- Returns:
- the analytics component
-
onTaskRemoved
public void onTaskRemoved(android.content.Intent rootIntent)
Description copied from interface:MediaPlayback
This is called when theMediaPlaybackService
is currently running and the user has removed a task that comes from the service's application.- Specified by:
onTaskRemoved
in interfaceMediaPlayback<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 interfaceMediaPlayback<android.media.MediaPlayer>
- 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 interfaceMediaPlayback<android.media.MediaPlayer>
-
isPlaying
public boolean isPlaying()
- Specified by:
isPlaying
in interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<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 interfaceMediaPlayback<android.media.MediaPlayer>
-
addAll
public void addAll(java.util.Collection<Video> videos)
Description copied from interface:MediaPlayback
Add all videos in the collection to the end of the list.- Specified by:
addAll
in interfaceMediaPlayback<android.media.MediaPlayer>
- Parameters:
videos
- The videos to append.
-
addAll
public void addAll(int index, java.util.Collection<Video> videos)
Description copied from interface:MediaPlayback
Inserts all videos in the collection at the specified index.- Specified by:
addAll
in interfaceMediaPlayback<android.media.MediaPlayer>
-
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 interfaceMediaPlayback<android.media.MediaPlayer>
- 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 interfaceMediaPlayback<android.media.MediaPlayer>
- Parameters:
videoPath
- HTTP path to the videolanguageCodeCaptionsMap
- 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 interfaceMediaPlayback<android.media.MediaPlayer>
-
getCurrentIndex
public int getCurrentIndex()
Description copied from interface:MediaPlayback
Gets the index from the current video- Specified by:
getCurrentIndex
in interfaceMediaPlayback<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 interfaceMediaPlayback<android.media.MediaPlayer>
-
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 interfaceMediaPlayback<android.media.MediaPlayer>
- 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 interfaceMediaPlayback<android.media.MediaPlayer>
-
getBufferPercentage
public int getBufferPercentage()
Description copied from interface:MediaPlayback
Returns the buffer percentage- Specified by:
getBufferPercentage
in interfaceMediaPlayback<android.media.MediaPlayer>
-
getVolume
public float getVolume()
- Specified by:
getVolume
in interfaceMediaPlayback<android.media.MediaPlayer>
-
isSourceSet
public boolean isSourceSet()
Description copied from interface:MediaPlayback
Returns if a source has been set- Specified by:
isSourceSet
in interfaceMediaPlayback<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 interfaceMediaPlayback<android.media.MediaPlayer>
-
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 interfaceMediaPlayback<android.media.MediaPlayer>
-
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 interfaceMediaPlayback<android.media.MediaPlayer>
-
-