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 classMediaPlayerPlayback.OnSetSourceListenerprotected classMediaPlayerPlayback.OnWillChangeVideoListener
-
Field Summary
Fields Modifier and Type Field Description booleanisPlayingForTestingprotected SourcenextSourceprotected VideonextVideoandroid.media.MediaPlayer.OnBufferingUpdateListeneronBufferingUpdateListenerandroid.media.MediaPlayer.OnCompletionListeneronCompletionListenerandroid.media.MediaPlayer.OnErrorListeneronErrorListenerandroid.media.MediaPlayer.OnInfoListeneronInfoListenerandroid.media.MediaPlayer.OnPreparedListeneronPreparedListenerandroid.media.MediaPlayer.OnSeekCompleteListeneronSeekCompleteListenerprotected intprogressIntervalprotected 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 voidadd(int index, Video video)Adds the video to the video list at the specified index.voidadd(Video video)Adds the video to the end of the video list.voidaddAll(int index, java.util.Collection<Video> videos)Inserts all videos in the collection at the specified index.voidaddAll(java.util.Collection<Video> videos)Add all videos in the collection to the end of the list.voidclear()Removes all videos from the list.voiddestroyPlayer()Destroys the current player and releases it from memory.voidemitErrorEvent(java.lang.String message)Emits an error event with the message passed in the event's propertiesvoidemitErrorEvent(java.lang.String message, java.lang.Exception exception)Emits an error event including the message passed and the exception in the propertiesAnalyticsgetAnalytics()Returns the analytics component, the part of the player that monitors and tracks video playback and engagement.intgetBufferPercentage()Returns the buffer percentageintgetCurrentIndex()Gets the index from the current videolonggetCurrentPosition()Returns the current playhead position of the underlying video player.SourcegetCurrentSource()Get the current source for theVideo.VideogetCurrentVideo()Get the currently playing video.longgetLiveEdge()Obtains the playhead position of the "live edge".PlaybackNotificationgetNotification()Get the object which handles showing an on-going player notification.android.media.MediaPlayergetPlayer()Get the player used for media playback.java.util.List<Video>getPlaylist()Returns a immutable copy of the video list.DefaultSourceSelectionControllergetSourceController()The source selector which uses a delegate to select sources.VideogetVideoAt(int index)Gets a video from the video list at the specified indexfloatgetVolume()booleanhasDvr()Indicates if Live with DVR is supported.booleanisCurrentVideo360Mode()Returns true if the video is a 360 video otherwise returns falsebooleanisInLiveEdge()Checks the current playhead position with the live edge position and determines if it is in live edge.booleanisLive()Provides a default for handling live videos.booleanisPlaying()booleanisPlayingAudioOnly()Check if the player is currently playing and the media is audio-only.booleanisSourceSet()Returns if a source has been setvoidonTaskRemoved(android.content.Intent rootIntent)This is called when theMediaPlaybackServiceis currently running and the user has removed a task that comes from the service's application.voidopenCurrentVideoSource()Prepares the player to play the current video source.voidopenVideo(Video video, Source source)Creates, configures, and prepares a new instance of MediaPlaybackvoidremove(int index)Removes the video at the specified index.voidsetCurrentIndex(int index)Sets the current video to the specified index.voidsetProgressInterval(int progressInterval)Sets the the interval in milliseconds at which to fire PROGRESS events during playback.VideosetVideoPath(java.lang.String path)Replaces player content with the video at the specified path.VideosetVideoPath(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.voidsetVideoSource(Video video, Source source)Sets the video source that will be used for playback.protected voidstartUpdater()protected voidstopUpdater()-
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:MediaPlaybackCreates, configures, and prepares a new instance of MediaPlayback- Specified by:
openVideoin 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:
openCurrentVideoSourcein interfaceMediaPlayback<android.media.MediaPlayer>
-
getSourceController
public DefaultSourceSelectionController getSourceController()
Description copied from interface:MediaPlaybackThe source selector which uses a delegate to select sources.- Specified by:
getSourceControllerin 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:
destroyPlayerin 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:
setVideoSourcein 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:MediaPlaybackGet the player used for media playback.- Specified by:
getPlayerin interfaceMediaPlayback<android.media.MediaPlayer>- Returns:
- The media player.
-
getCurrentVideo
public Video getCurrentVideo()
Description copied from interface:MediaPlaybackGet the currently playing video.- Specified by:
getCurrentVideoin interfaceMediaPlayback<android.media.MediaPlayer>- Returns:
- The current media object.
-
getCurrentSource
public Source getCurrentSource()
Description copied from interface:MediaPlaybackGet the current source for theVideo.- Specified by:
getCurrentSourcein interfaceMediaPlayback<android.media.MediaPlayer>- Returns:
- The source used for playback.
-
isPlayingAudioOnly
public boolean isPlayingAudioOnly()
Description copied from interface:MediaPlaybackCheck if the player is currently playing and the media is audio-only.- Specified by:
isPlayingAudioOnlyin 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:MediaPlaybackReturns the analytics component, the part of the player that monitors and tracks video playback and engagement.- Specified by:
getAnalyticsin interfaceMediaPlayback<android.media.MediaPlayer>- Returns:
- the analytics component
-
onTaskRemoved
public void onTaskRemoved(android.content.Intent rootIntent)
Description copied from interface:MediaPlaybackThis is called when theMediaPlaybackServiceis currently running and the user has removed a task that comes from the service's application.- Specified by:
onTaskRemovedin 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:MediaPlaybackGet the object which handles showing an on-going player notification.- Specified by:
getNotificationin 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:MediaPlaybackReturns a immutable copy of the video list.- Specified by:
getPlaylistin interfaceMediaPlayback<android.media.MediaPlayer>
-
isPlaying
public boolean isPlaying()
- Specified by:
isPlayingin 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:
hasDvrin interfaceMediaPlayback<android.media.MediaPlayer>- Returns:
TRUEiff 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:
isLivein interfaceMediaPlayback<android.media.MediaPlayer>- Returns:
TRUEiff live video is supported.
-
getLiveEdge
public long getLiveEdge()
Obtains the playhead position of the "live edge".- Specified by:
getLiveEdgein 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:
isInLiveEdgein 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_UNSETwill returned.- Specified by:
getCurrentPositionin 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:
setProgressIntervalin interfaceMediaPlayback<android.media.MediaPlayer>- Parameters:
progressInterval- the PROGRESS interval in milliseconds
-
add
public void add(Video video)
Description copied from interface:MediaPlaybackAdds the video to the end of the video list.- Specified by:
addin interfaceMediaPlayback<android.media.MediaPlayer>
-
add
public void add(int index, Video video)Description copied from interface:MediaPlaybackAdds the video to the video list at the specified index.- Specified by:
addin interfaceMediaPlayback<android.media.MediaPlayer>
-
addAll
public void addAll(java.util.Collection<Video> videos)
Description copied from interface:MediaPlaybackAdd all videos in the collection to the end of the list.- Specified by:
addAllin 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:MediaPlaybackInserts all videos in the collection at the specified index.- Specified by:
addAllin interfaceMediaPlayback<android.media.MediaPlayer>
-
setVideoPath
public Video setVideoPath(java.lang.String path)
Description copied from interface:MediaPlaybackReplaces player content with the video at the specified path.- Specified by:
setVideoPathin 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:MediaPlaybackReplace player content with the video and captions at the specified paths.- Specified by:
setVideoPathin 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:MediaPlaybackGets a video from the video list at the specified index- Specified by:
getVideoAtin interfaceMediaPlayback<android.media.MediaPlayer>
-
getCurrentIndex
public int getCurrentIndex()
Description copied from interface:MediaPlaybackGets the index from the current video- Specified by:
getCurrentIndexin 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:MediaPlaybackSets the current video to the specified index.- Specified by:
setCurrentIndexin interfaceMediaPlayback<android.media.MediaPlayer>
-
remove
public void remove(int index) throws java.lang.IndexOutOfBoundsExceptionDescription copied from interface:MediaPlaybackRemoves the video at the specified index.- Specified by:
removein 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:MediaPlaybackRemoves all videos from the list.- Specified by:
clearin interfaceMediaPlayback<android.media.MediaPlayer>
-
getBufferPercentage
public int getBufferPercentage()
Description copied from interface:MediaPlaybackReturns the buffer percentage- Specified by:
getBufferPercentagein interfaceMediaPlayback<android.media.MediaPlayer>
-
getVolume
public float getVolume()
- Specified by:
getVolumein interfaceMediaPlayback<android.media.MediaPlayer>
-
isSourceSet
public boolean isSourceSet()
Description copied from interface:MediaPlaybackReturns if a source has been set- Specified by:
isSourceSetin interfaceMediaPlayback<android.media.MediaPlayer>
-
isCurrentVideo360Mode
public boolean isCurrentVideo360Mode()
Description copied from interface:MediaPlaybackReturns true if the video is a 360 video otherwise returns false- Specified by:
isCurrentVideo360Modein interfaceMediaPlayback<android.media.MediaPlayer>
-
emitErrorEvent
public void emitErrorEvent(java.lang.String message)
Description copied from interface:MediaPlaybackEmits an error event with the message passed in the event's properties- Specified by:
emitErrorEventin interfaceMediaPlayback<android.media.MediaPlayer>
-
emitErrorEvent
public void emitErrorEvent(java.lang.String message, java.lang.Exception exception)Description copied from interface:MediaPlaybackEmits an error event including the message passed and the exception in the properties- Specified by:
emitErrorEventin interfaceMediaPlayback<android.media.MediaPlayer>
-
-