-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Labels
Description
Bug
I am using ServerSideAdInsertionMediaSource and i can't figure out how to show ad overlay instead of player seekbar
also when i reach ad mark, app freezes suddenly and not responded again
please support
adsMediaSource = ServerSideAdInsertionMediaSource(mediaSource, this refer to onadPlaybackStateUpdatedrequest)
player = ExoPlayer.Builder(context).setMediaSourceFactory(DefaultMediaSourceFactory(context))
.build()
player?.addListener(this)
player?.playWhenReady = true
exoPlayerView.player = player
player?.setMediaSource(adsMediaSource!!)
player?.seekTo(playbackPosition)
player?.playWhenReady = playWhenReady
player?.prepare()
// @SuppressLint("UnsafeOptInUsageError")
override fun onAdPlaybackStateUpdateRequested(contentTimeline: Timeline): Boolean {
val adStatesBuilder = ImmutableMap.builder<Any, AdPlaybackState>()
(0 until contentTimeline.periodCount).forEach { periodIndex ->
val uid = contentTimeline.getUidOfPeriod(periodIndex)
var adPlaybackState = AdPlaybackState(uid, 5 * C.MICROS_PER_SECOND)
.withAdCount(0,1)
adPlaybackStateMap.put(contentTimeline.getUidOfPeriod(0),adPlaybackState)
adsMediaSource?.setAdPlaybackStates(adPlaybackStateMap.build(),
contentTimeline)
adStatesBuilder.put(uid, adPlaybackState) // should be AdPlaybackState.NONE
}
adsMediaSource?.setAdPlaybackStates(adStatesBuilder.build(),contentTimeline)
return true
}