question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NPE when download manifest with DashUtil.loadManifest

See original GitHub issue

Hi Team! i want to download offline license key, ant then save it to local database. i created such helper-class

class LicenseDownloader @Inject constructor(
    private val context: Context
) {

    private val userAgent = Util.getUserAgent(context, "ua")
    private val drmSessionEventListener = object : DrmSessionEventListener.EventDispatcher() {}

    private val httpDataSourceFactory = DefaultHttpDataSource.Factory().setUserAgent(userAgent)
    private val dataSource = httpDataSourceFactory.createDataSource()

    suspend fun downloadLicense(
        manifestUrl: String,
        licenseUrl: String
    ): ByteArray {

        val offlineLicenseHelper = OfflineLicenseHelper
            .newWidevineInstance(licenseUrl, httpDataSourceFactory, drmSessionEventListener)

        return runCatching {
            withContext(Dispatchers.IO) {

                val dashManifest = DashUtil.loadManifest(
                    dataSource,
                    Uri.parse(manifestUrl)
                )

                val drmInitData =
                    DashUtil.loadFormatWithDrmInitData(dataSource, dashManifest.getPeriod(0))
                val license = offlineLicenseHelper.downloadLicense(drmInitData!!)

                license
            }
        }.also {

            offlineLicenseHelper.release()
        }.getOrElse {
            Timber.e(it.localizedMessage)

            ByteArray(0)
        }
    }
}

after start application, first call of licenseDownloader.downloadLicense(manifestUrl, licenseUrl) ends success, but second call throws NPE with message java.lang.NullPointerException: wrapped.getHeaderField(key) must not be null

W/System.err: java.lang.NullPointerException: wrapped.getHeaderField(key) must not be null
2022-02-16 03:41:57.229 14002-14162/com.xxxxxxxx W/System.err:     at com.android.tools.appinspection.network.httpurl.TrackedHttpURLConnection.getHeaderField(TrackedHttpURLConnection.kt:317)
2022-02-16 03:41:57.229 14002-14162/com.xxxxxxxx W/System.err:     at com.android.tools.appinspection.network.httpurl.HttpsURLConnectionWrapper.getHeaderField(HttpsURLConnectionWrapper.kt:182)
2022-02-16 03:41:57.229 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.isCompressed(DefaultHttpDataSource.java:774)
2022-02-16 03:41:57.229 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:405)
2022-02-16 03:41:57.229 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.DataSourceInputStream.checkOpened(DataSourceInputStream.java:101)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.DataSourceInputStream.open(DataSourceInputStream.java:64)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.ParsingLoadable.load(ParsingLoadable.java:177)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.upstream.ParsingLoadable.load(ParsingLoadable.java:69)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.google.android.exoplayer2.source.dash.DashUtil.loadManifest(DashUtil.java:75)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.xxxxxxxx.player.LicenseDownloader$downloadLicense$2.invokeSuspend(LicenseDownloader.kt:78)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.xxxxxxxx.player.LicenseDownloader$downloadLicense$2.invoke(Unknown Source:10)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.xxxxxxxx.player.LicenseDownloader.downloadLicense(LicenseDownloader.kt:74)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at com.xxxxxxxx.utils.DownloadHelper$updateAvailabilityStatus$$inlined$forEach$lambda$1$1.invokeSuspend(DownloadHelper.kt:127)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2022-02-16 03:41:57.230 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2022-02-16 03:41:57.231 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
2022-02-16 03:41:57.231 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
2022-02-16 03:41:57.231 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
2022-02-16 03:41:57.231 14002-14162/com.xxxxxxxx W/System.err:     at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

Exception thrown in the line DashUtil.loadManifest.

what is the problem? help me please! i spend about 2 days, but does not find solution (((

Android 10 (Emulator and other devices) ExoPlayer v2.14.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
icbakercommented, Feb 17, 2022

This is a bug in Android Studio’s implementation of URLConnection: https://issuetracker.google.com/219572925

1reaction
schnaps1981commented, Feb 22, 2022

@Kolyall that is no problem of exoplayer.

you can try to use okhttp datasource

  1. you need import dependency "com.google.android.exoplayer:extension-okhttp:**xx.xx.xx (your exoplayer version)**"

  2. then

val client = OkHttpClient.Builder().build()

val okhttpDataSourceFactory = OkHttpDataSource.Factory(okHttpClient)

val okHttpDataSource = okhttpDataSourceFactory.createDataSource()`

val drmInitData = DashUtil.loadFormatWithDrmInitData(okHttpDataSource, dashManifest.getPeriod(0))

it works fine for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPE when download manifest with DashUtil.loadManifest
Hi Team! i want to download offline license key, ant then save it to local database. i created such helper-class class LicenseDownloader @Inject ......
Read more >
request offline viewing license for local asset #2646 - GitHub
Issue description. Fail to process local storage MPD file - DashUtil.loadManifest is not suitable to process local storage file. DashUtil.
Read more >
DashMediaSource.Factory - Android Developers
A factory for DataSource instances that will be used to load manifest and media data. Factory. Factory( chunkSourceFactory: DashChunkSource.
Read more >
Load Dash Manifest with DRM content with ExoPlayer
I have a dash manifest which needs to be loaded in ExoPlayer, which is also DRM protected. I can't seem to find any...
Read more >
DashUtil.loadManifest - Java - Tabnine
Loads DrmInitData for a given period in a DASH manifest. getFirstRepresentation · loadChunkIndex. Loads initialization and index data for the representation and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found