Skip to content

Commit

Permalink
Use adbreakbegin/end to update isPlayingAd
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Aug 28, 2024
1 parent 2611748 commit e5bde31
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions ui/src/main/java/com/theoplayer/android/ui/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.theoplayer.android.api.cast.Cast
import com.theoplayer.android.api.cast.chromecast.PlayerCastState
import com.theoplayer.android.api.error.THEOplayerException
import com.theoplayer.android.api.event.EventListener
import com.theoplayer.android.api.event.ads.AdBeginEvent
import com.theoplayer.android.api.event.ads.AdEvent
import com.theoplayer.android.api.event.ads.AdsEventTypes
import com.theoplayer.android.api.event.chromecast.CastErrorEvent
Expand Down Expand Up @@ -348,11 +347,8 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
videoHeight = player?.videoHeight ?: 0
}

private fun updatePlayingAd(event: AdEvent<*>? = null) {
playingAd = when (event) {
is AdBeginEvent -> true
else -> false
}
private fun updatePlayingAd() {
playingAd = ads?.isPlaying ?: false
}

private val playListener = EventListener<PlayEvent> { updateCurrentTimeAndPlaybackState() }
Expand All @@ -366,9 +362,7 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
private val readyStateChangeListener =
EventListener<ReadyStateChangeEvent> { updateCurrentTimeAndPlaybackState() }
private val resizeListener = EventListener<ResizeEvent> { updateVideoWidthAndHeight() }
private val adListener = EventListener<AdEvent<*>> {
updatePlayingAd(it)
}
private val adListener = EventListener<AdEvent<*>> { updatePlayingAd() }
private val sourceChangeListener = EventListener<SourceChangeEvent> {
_source = player?.source
error = null
Expand Down Expand Up @@ -686,9 +680,9 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
TextTrackListEventTypes.TRACKLISTCHANGE,
textTrackListChangeListener
)
ads?.addEventListener(AdsEventTypes.AD_BEGIN, adListener)
ads?.addEventListener(AdsEventTypes.AD_BREAK_BEGIN, adListener)
ads?.addEventListener(AdsEventTypes.AD_SKIP, adListener)
ads?.addEventListener(AdsEventTypes.AD_END, adListener)
ads?.addEventListener(AdsEventTypes.AD_BREAK_END, adListener)
cast?.chromecast?.addEventListener(
ChromecastEventTypes.STATECHANGE,
chromecastStateChangeListener
Expand Down Expand Up @@ -752,8 +746,9 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
TextTrackListEventTypes.TRACKLISTCHANGE,
textTrackListChangeListener
)
ads?.removeEventListener(AdsEventTypes.AD_BEGIN, adListener)
ads?.removeEventListener(AdsEventTypes.AD_END, adListener)
ads?.removeEventListener(AdsEventTypes.AD_BREAK_BEGIN, adListener)
ads?.removeEventListener(AdsEventTypes.AD_SKIP, adListener)
ads?.removeEventListener(AdsEventTypes.AD_BREAK_END, adListener)
cast?.chromecast?.removeEventListener(
ChromecastEventTypes.STATECHANGE,
chromecastStateChangeListener
Expand Down

0 comments on commit e5bde31

Please sign in to comment.