0

I'm using Exoplayer (androidx v1.0.1) to implement dynamic ad insertion (DAI) and i must set some custom headers when "live" in playing and remove those headers when ads rolling.

Without headers "live" will not play and i want to remove them when ads rolling to avoid any conflig with google

Right now i set them globaly:

mDefaultHttpDataSourceFactory = DefaultHttpDataSource.Factory()
        .setAllowCrossProtocolRedirects(true)
        .setDefaultRequestProperties(mCustomHeaders)
        .setUserAgent(mContext.getString(R.string.player_name))
        .setTransferListener(
            DefaultBandwidthMeter.Builder(mContext)
                .setResetOnNetworkTypeChange(false)
                .build())

What listener(s) or method(s) should i use to add/remove those headers? Even on prefetch

Thanks

BejanCorneliu
  • 65
  • 3
  • 13

1 Answers1

1

Adding this will intercept any prefetch request

val dataSourceFactory2: DataSource.Factory =
        ResolvingDataSource.Factory(mDefaultHttpDataSourceFactory)
        { dataSpec: DataSpec ->
            if (dataSpec.uri.toString().contains("domain.com")) {
                dataSpec.withAdditionalHeaders(mCustomHeaders)
            } else {
                dataSpec.withRequestHeaders(HashMap())
            }
        }
BejanCorneliu
  • 65
  • 3
  • 13