Skip to content

Commit

Permalink
fix: seeking not properly tracked on ExoPlayer 2.18 and 2.19 (#343) (#…
Browse files Browse the repository at this point in the history
…344)

## Fixes

* fix: seeking not properly tracked on ExoPlayer 2.18 and 2.19 (#343)



Co-authored-by: Emily Dixon <edixon@mux.com>
Co-authored-by: GitHub <noreply@github.com>
  • Loading branch information
daytime-em and web-flow authored Nov 19, 2023
1 parent 9970eef commit fa8166d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private class ExoAnalyticsListener(player: ExoPlayer, val collector: MuxStateCol
eventTime: AnalyticsListener.EventTime,
reason: Int
) {
collector.handlePositionDiscontinuity(reason)
collector.handlePositionDiscontinuityBefore218(reason)
}

@Suppress("OVERRIDE_DEPRECATION") // Not worth making a new variant over (deprecated 2.12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private class ExoAnalyticsListener(player: ExoPlayer, val collector: MuxStateCol
eventTime: AnalyticsListener.EventTime,
reason: Int
) {
collector.handlePositionDiscontinuity(reason)
collector.handlePositionDiscontinuityBefore218(reason)
}

@Suppress("OVERRIDE_DEPRECATION") // Not worth making a new variant over (deprecated 2.12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.google.android.exoplayer2.source.LoadEventInfo
import com.google.android.exoplayer2.source.MediaLoadData
import com.google.android.exoplayer2.source.TrackGroupArray
import com.google.android.exoplayer2.video.VideoSize
import com.mux.stats.sdk.muxstats.MuxPlayerState
import com.mux.stats.sdk.muxstats.MuxStateCollector
import java.io.IOException

Expand Down Expand Up @@ -38,13 +39,15 @@ private class ExoAnalyticsListener(player: ExoPlayer, val collector: MuxStateCol
//todo
}

// TODO: Requires exo 2.12
override fun onPlayWhenReadyChanged(
eventTime: EventTime,
playWhenReady: Boolean,
reason: Int
) {
player?.let {
if (collector.muxPlayerState == MuxPlayerState.SEEKED) {
collector.seeked(false)
}
collector.handleExoPlaybackState(it.playbackState, it.playWhenReady)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private class ExoAnalyticsListener(player: ExoPlayer, val collector: MuxStateCol
eventTime: AnalyticsListener.EventTime,
reason: Int
) {
collector.handlePositionDiscontinuity(reason)
collector.handlePositionDiscontinuityBefore218(reason)
}

@Suppress("OVERRIDE_DEPRECATION") // Not worth making a new variant over (deprecated 2.12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,32 @@ private val hlsExtensionAvailable: Boolean by lazy {
internal fun isHlsExtensionAvailable() = hlsExtensionAvailable

/**
* Handles an ExoPlayer position discontinuity
* Handles an ExoPlayer position discontinuity.
*/
@JvmSynthetic // Hides from java
@JvmSynthetic
internal fun MuxStateCollector.handlePositionDiscontinuity(reason: Int) {
// todo - other versions too
when (reason) {
Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT, Player.DISCONTINUITY_REASON_SEEK -> {
// Called when seeking starts. Player will move to READY when seeking is over
if (mediaHasVideoTrack != false) {
seeking()
} else {
seeked(false)
}
}

else -> {} // ignored
}
}

/**
* Handles an ExoPlayer position discontinuity.
* This should only be used for ExoPlayers before version 2.18. Due to behavior changes coinciding
* with Exo 2.18/media3 1.0
*/
@JvmSynthetic // Hides from java
internal fun MuxStateCollector.handlePositionDiscontinuityBefore218(reason: Int) {
when (reason) {
Player.DISCONTINUITY_REASON_SEEK -> {
// If they seek while paused, this is how we know the seek is complete
Expand Down Expand Up @@ -98,6 +120,10 @@ internal fun MuxStateCollector.handleExoPlaybackState(
}
}
Player.STATE_READY -> {
if (muxPlayerState == MuxPlayerState.SEEKING) {
// TODO <em> playing() and pause() handle rebuffering, why not also seeking
seeked(false)
}
if (playWhenReady) {
playing()
} else if (muxPlayerState != MuxPlayerState.PAUSED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ class AdsImaSDKListener private constructor(
AdEvent.AdEventType.LOADED -> {}
AdEvent.AdEventType.CONTENT_PAUSE_REQUESTED -> {
// Send pause event if we are currently playing or preparing to play content
if (stateCollector.muxPlayerState.oneOf(MuxPlayerState.PLAY, MuxPlayerState.PLAYING)) {
if (stateCollector.muxPlayerState.oneOf(
MuxPlayerState.PLAY,
MuxPlayerState.PLAYING,
MuxPlayerState.REBUFFERING,
MuxPlayerState.SEEKING
)) {
stateCollector.pause()
}
sendPlayOnStarted = false
Expand Down Expand Up @@ -143,8 +148,12 @@ class AdsImaSDKListener private constructor(
// End the ad break, and then toggle playback state to ensure that
// we get a play/playing after the ads.
dispatchAdPlaybackEvent(AdBreakEndEvent(null), ad)
val oldPlayWhenReady = player.playWhenReady
player.playWhenReady = false
stateCollector.finishedPlayingAds()
if(oldPlayWhenReady) {
stateCollector.playing()
}
player.playWhenReady = true
}
AdEvent.AdEventType.PAUSED -> {
Expand Down

0 comments on commit fa8166d

Please sign in to comment.