I'm using DownloadService from Exoplayer to download HLS videos. https://exoplayer.dev/downloading-media.html
The links I'm supplying are pre-authorized links for downloading HLS videos. Sometimes I'm seeing an app crash on 401. Stack below:
Exception com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 401
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open (SourceFile:47)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open (SourceFile:21)
at com.google.android.exoplayer2.upstream.StatsDataSource.open (SourceFile:3)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.checkOpened (SourceFile:2)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.open
at com.google.android.exoplayer2.upstream.ParsingLoadable.load (SourceFile:9)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run (SourceFile:6)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:764)
I tried to reproduce this by giving expired links. The exoplayer downloader is handling it gracefully. I'm confused now where to look ? What could be the possible reason ?
Here's the implemenatation for DownloadManager, where I'm giving Executor and DataSource:
private fun getManager(
context: Context,
databaseProvider: ExoDatabaseProvider,
simpleCache: SimpleCache,
downloadListener: OPDownloadListener,
threadPoolSize: Int
): DownloadManager {
val manager = DownloadManager(
context,
DefaultDownloadIndex(databaseProvider),
DefaultDownloaderFactory(
CacheDataSource.Factory()
.setCache(simpleCache)
.setCacheKeyFactory(OPDownloadCacheKeyFactory())
.setUpstreamDataSourceFactory(getHttpDataSourceFactory(context)),
Executors.newFixedThreadPool(threadPoolSize)
)
)
manager.addListener(downloadListener)
manager.maxParallelDownloads = MAX_PARALLEL_DOWNLOADS
return manager
I was not expecting the crash, and if it is, it should happen every time.