Class MediaSessionHelper
- All Implemented Interfaces:
EventListener,AdvertisingEvents.OnAdCompleteListener,AdvertisingEvents.OnAdErrorListener,AdvertisingEvents.OnAdPlayListener,AdvertisingEvents.OnAdSkippedListener,VideoPlayerEvents.OnBufferListener,VideoPlayerEvents.OnErrorListener,VideoPlayerEvents.OnPauseListener,VideoPlayerEvents.OnPlaylistCompleteListener,VideoPlayerEvents.OnPlayListener,VideoPlayerEvents.OnPlaylistItemListener,VideoPlayerEvents.OnPlaylistItemMetadataChangedListener,VideoPlayerEvents.OnSeekedListener,VideoPlayerEvents.OnTimeListener
-
Constructor Summary
ConstructorsModifierConstructorDescriptionMediaSessionHelper(android.content.Context context, NotificationHelper notificationHelper, ServiceMediaApi serviceMediaApi) protectedMediaSessionHelper(android.content.Context context, NotificationHelper notificationHelper, ServiceMediaApi serviceMediaApi, BGAFactory bgaFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidonAdComplete(AdCompleteEvent adCompleteEvent) Fired whenever an ad has completed playback.voidonAdError(AdErrorEvent adErrorEvent) Fired whenever an error prevents the ad from playing.voidonAdPlay(AdPlayEvent adPlayEvent) Fired whenever an ad starts playing or when an ad is unpaused.voidonAdSkipped(AdSkippedEvent adSkippedEvent) Fired whenever an ad has been skipped.voidonBitmapReady(android.graphics.Bitmap bitmap) voidonBuffer(BufferEvent bufferEvent) Fired when the player enters the BUFFERING state.voidonError(ErrorEvent errorEvent) Fired when a media error has occurred, causing the player to stop playback and go into IDLE mode.voidonPause(PauseEvent pauseEvent) Fired when the player enters the PAUSED state.voidFired when the player enters the PLAYING state.voidonPlaylistComplete(PlaylistCompleteEvent playlistCompleteEvent) Fired when the player is done playing all items in the playlist.voidonPlaylistItem(PlaylistItemEvent playlistItemEvent) Fired when the playlist index changes to a new playlist item.voidFired when playlist item metadata (title, description, or image) is updated viaJWPlayer.setPlaylistItemMetadata(String, String, String).voidonSeeked(SeekedEvent seekedEvent) Re-anchors the media session immediately after a seek, in whatever state the player is in.voidRe-anchors the media session's position while playing.protected voidupdateMediaSessionWith(JWPlayer player)
-
Constructor Details
-
MediaSessionHelper
public MediaSessionHelper(android.content.Context context, NotificationHelper notificationHelper, ServiceMediaApi serviceMediaApi) -
MediaSessionHelper
protected MediaSessionHelper(android.content.Context context, NotificationHelper notificationHelper, ServiceMediaApi serviceMediaApi, BGAFactory bgaFactory)
-
-
Method Details
-
updateMediaSessionWith
-
onPlaylistItem
Description copied from interface:VideoPlayerEvents.OnPlaylistItemListenerFired when the playlist index changes to a new playlist item. This event occurs before the player begins playing the new playlist item.- Specified by:
onPlaylistItemin interfaceVideoPlayerEvents.OnPlaylistItemListener- Parameters:
playlistItemEvent- The payload that accompanies the onPlaylistItem() event.
-
onPlaylistItemMetadataChanged
Description copied from interface:VideoPlayerEvents.OnPlaylistItemMetadataChangedListenerFired when playlist item metadata (title, description, or image) is updated viaJWPlayer.setPlaylistItemMetadata(String, String, String).- Specified by:
onPlaylistItemMetadataChangedin interfaceVideoPlayerEvents.OnPlaylistItemMetadataChangedListener- Parameters:
event- The payload that accompanies the onPlaylistItemMetadataChanged() event.
-
onError
Description copied from interface:VideoPlayerEvents.OnErrorListenerFired when a media error has occurred, causing the player to stop playback and go into IDLE mode.- Specified by:
onErrorin interfaceVideoPlayerEvents.OnErrorListener- Parameters:
errorEvent- The payload that accompanies the onError() event.
-
onAdComplete
Description copied from interface:AdvertisingEvents.OnAdCompleteListenerFired whenever an ad has completed playback.Supported for VAST and IMA.
- Specified by:
onAdCompletein interfaceAdvertisingEvents.OnAdCompleteListener- Parameters:
adCompleteEvent- The payload that accompanies the onAdComplete() event.
-
onAdSkipped
Description copied from interface:AdvertisingEvents.OnAdSkippedListenerFired whenever an ad has been skipped.Supported for VAST and IMA.
- Specified by:
onAdSkippedin interfaceAdvertisingEvents.OnAdSkippedListener- Parameters:
adSkippedEvent- The payload that accompanies the onAdSkipped() event.
-
onAdPlay
Description copied from interface:AdvertisingEvents.OnAdPlayListenerFired whenever an ad starts playing or when an ad is unpaused.- Specified by:
onAdPlayin interfaceAdvertisingEvents.OnAdPlayListener- Parameters:
adPlayEvent- The payload that accompanies the onAdPlay() event.
-
onAdError
Description copied from interface:AdvertisingEvents.OnAdErrorListenerFired whenever an error prevents the ad from playing.Supported for VAST and IMA.
- Specified by:
onAdErrorin interfaceAdvertisingEvents.OnAdErrorListener- Parameters:
adErrorEvent- The payload that accompanies the onAdError() event.
-
onBuffer
Description copied from interface:VideoPlayerEvents.OnBufferListenerFired when the player enters the BUFFERING state.- Specified by:
onBufferin interfaceVideoPlayerEvents.OnBufferListener- Parameters:
bufferEvent- The payload that accompanies the onBuffer() event.
-
onPause
Description copied from interface:VideoPlayerEvents.OnPauseListenerFired when the player enters the PAUSED state.- Specified by:
onPausein interfaceVideoPlayerEvents.OnPauseListener- Parameters:
pauseEvent- The payload that accompanies the onPause() event.
-
onPlay
Description copied from interface:VideoPlayerEvents.OnPlayListenerFired when the player enters the PLAYING state.- Specified by:
onPlayin interfaceVideoPlayerEvents.OnPlayListener- Parameters:
playEvent- The payload that accompanies the onPlay() event.
-
onPlaylistComplete
Description copied from interface:VideoPlayerEvents.OnPlaylistCompleteListenerFired when the player is done playing all items in the playlist. However, if the repeat option is set true, this is never fired.- Specified by:
onPlaylistCompletein interfaceVideoPlayerEvents.OnPlaylistCompleteListener- Parameters:
playlistCompleteEvent- The payload that accompanies the onPlaylistComplete() event.
-
onBitmapReady
public void onBitmapReady(android.graphics.Bitmap bitmap) -
onTime
Re-anchors the media session's position while playing.updatePlaybackState(com.jwplayer.pub.api.PlayerState)only runs on state transitions, so between them the system had nothing but its own extrapolation to go on and drifted from the real playhead — and a seek during playback was not reflected at all until the next pause or buffer. Time events give a cheap, already-available tick to correct both.Deliberately does not rebuild the notification:
NotificationHelperbakes its content at build time and nothing shown there changes with position, so rebuilding it several times a second would be pure cost.- Specified by:
onTimein interfaceVideoPlayerEvents.OnTimeListener- Parameters:
timeEvent- The payload that accompanies the onTime() event.
-
onSeeked
Re-anchors the media session immediately after a seek, in whatever state the player is in.Needed because the periodic re-anchor in
onTime(com.jwplayer.pub.api.events.TimeEvent)only runs while PLAYING. For VOD the time loop is stopped while paused (DVR keeps a slow loop, but the PLAYING gate excludes it either way). A seek requested from the lock screen or notification —ServiceMediaApi.onSeekTo, which the session advertises via ACTION_SEEK_TO — would otherwise leave the session holding the pre-seek anchor, so the scrubber would snap back to where it was and stay there until the next play. That is the second half of this ticket's own verification step.Deliberately not throttled: a seek is user-initiated and infrequent, and the whole point is that it takes effect at once rather than up to a second later. It does stamp the throttle so the next periodic tick is measured from here. Notification is not rebuilt, for the same reason as
onTime(com.jwplayer.pub.api.events.TimeEvent).- Specified by:
onSeekedin interfaceVideoPlayerEvents.OnSeekedListener- Parameters:
seekedEvent- The payload that accompanies the onSeeked() event.
-