Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServerSideAdInsertionMediaSource how to show adsOverlay #11290

Open
moniqueeeeee opened this issue Sep 13, 2023 · 7 comments
Open

ServerSideAdInsertionMediaSource how to show adsOverlay #11290

moniqueeeeee opened this issue Sep 13, 2023 · 7 comments
Assignees
Labels

Comments

@moniqueeeeee
Copy link

moniqueeeeee commented Sep 13, 2023

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
}
@moniqueeeeee
Copy link
Author

please can you support how to show ads overlay using ServerSideAdInsertionMediaSource , do i need to make custom loader ?

@marcbaechinger
Copy link
Contributor

ServerSideAdInsertionMediaSource doesn't provide such a functionality.

PlayerView has a method getAdViewGroup() that gives you a ViewGroup in which you can insert your own views.
Is this what you are looking for?

@moniqueeeeee
Copy link
Author

moniqueeeeee commented Sep 14, 2023

@marcbaechinger Thanks marc,

can you explian more how i can handle the ad period , should i make custom adloader and if yes how i can handle it ?

i want to have control on ad period but i dont know how to achieve it ?

one more question please , how i use "getAdViewGroup" in whice state i can use it ?

thanks so much

@marcbaechinger
Copy link
Contributor

how i use "getAdViewGroup" in whice state i can use it ?

I'd expect you want to get the view group at the beginning with playerView. getAdViewGroup() and then insert your views that you hide until an ad is playing.

You can listen to Player.Listener.onPositionDiscontinuity() to figure out when an ad starts/ends playing.

@moniqueeeeee
Copy link
Author

Thanks so much

can you mention please how to check if ad started or ended in Player.Listener.onPositionDiscontinuity()

one more question please , is there any way to track (ad) in adGroup , if i have 3 ads in adgroup is there any way to track if ad is started or ended

@moniqueeeeee
Copy link
Author

@marcbaechinger
playbackState =
playbackState?.withNewAdGroup(index, adBreakGroup.timeOffsetUs)
?.withAdCount(index, 1)
?.withAdDurationsUs(index,
adBreakGroup.totalGroupDuration)
?.withIsServerSideInserted(/* adGroupIndex= */ index, true)

i have 3 ads in ad group whenever i change 1 to 3 app crash

@moniqueeeeee
Copy link
Author

@marcbaechinger please support how can i know if ad is started or ended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants