google / google/ExoPlayer

ServerSideAdInsertionMediaSource how to show adsOverlay

Open
#11,290 8 comments 1 reaction 1 assignee Claimed by @marcbaechinger View on GitHub
question
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

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()
(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
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.