Exoplayer with preroll and dynamic ad insertion

890 Views Asked by At

I want to make work my DASH stream with preroll and DAI. For now, I was able to make: DASH + preroll working and DASH + dai. But all three not

dash + dai :

val dashMediaSource = DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory)
            .createMediaSource(
                MediaItem.Builder()
                    .setUri(Uri.parse(URLDAI))  //diff
                    .setDrmConfiguration(
                        MediaItem.DrmConfiguration.Builder(drmSchemeUuid)
                            .setLicenseUri(DRM_LICENSE_URL).build()
                    )
                    .setMimeType(MimeTypes.APPLICATION_MPD)
                    .setTag(null)
                    .build()
            )

  playerView.setMediaSource(adsMediaSource)
    playerView.prepare()

dash + preroll

val dashMediaSource = DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory)
            .createMediaSource(
                MediaItem.Builder()
                    .setUri(Uri.parse(URL))  //diff
                    .setDrmConfiguration(
                        MediaItem.DrmConfiguration.Builder(drmSchemeUuid)
                            .setLicenseUri(DRM_LICENSE_URL).build()
                    )
                    .setMimeType(MimeTypes.APPLICATION_MPD)
                    .setTag(null)
                    .build()
            )

val dataSpec = DataSpec(Uri.parse(PREROLL))
val imaSdkSettings = ImaSdkFactory.getInstance().createImaSdkSettings()
val imaAdsLoader = ImaAdsLoader.Builder(this).setImaSdkSettings(imaSdkSettings).build()
imaAdsLoader.setPlayer(playerView)
val adsMediaSource = AdsMediaSource(mediaSource, dataSpec, 0, DefaultMediaSourceFactory(this), imaAdsLoader, binding.playerView)
playerView.setMediaSource(adsMediaSource)
playerView.prepare()

But if I combine both I get :

com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected IllegalArgumentException: null

How can I have all three workings: preroll + dai + dash ( drm widevine) in exoplayer 2.18.1?

Thanks

2

There are 2 best solutions below

0
On

Unfortunately no. They stated it here: https://developer.android.com/guide/topics/media/exoplayer/ad-insertion#:~:text=.release()-,Note,-%3A%20Currently%20only

These stream types are incompatible but you still can combine the features:

val imaAdsMediaSource = AdsMediaSource(
    mediaSource, // original content source
    DataSpec(Uri.parse(url)), // ads url will handle preroll
    listOf(url, mediaSource.mediaItem.mediaId), // sample object ID
    DefaultMediaSourceFactory(context)
        .setLocalAdInsertionComponents({ loader }, // use the builder: ImaAdsLoader.Builder
            { view }) // default groupView
        .setServerSideAdInsertionMediaSourceFactory(
            adsSSAIMediaSourceFactory // use the factory: ImaServerSideAdInsertionMediaSource.Factory
        ),
    loader
) { view }

So if you want to request ads (like non paid users) use this media source, if not, just keep the original content media source. This is the only wrapper that worked for me to handle different types of sources like Cronet, Hls, Dash, Akamai, Clippable and DRM

0
On

It might not like the .setTag(null) part; either remove that or provide String.

And I also find it strange that you access playerView ...and not player; for comparison:

player.setMediaSource(adsMediaSource)
player.prepare()