Open nikky12 opened 1 year ago
The DownloadService
needs to setup a DownloadManager
. Does it help if you set this up with a ResoilvingDataSource
somehow? You can then set the headers when the download starts and change the data spec accordingly.
DefaultHttpDataSource.Factory upstreamFactory = new DefaultHttpDataSource.Factory();
DataSource.Factory factory == new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return new ResolvingDataSource(
upstreamFactory.createDataSource(),
dataSpec ->
dataSpec.buildUpon().setHttpRequestHeaders(ImmutableMap.of("foo", "bar")).build());
}
};
DownloadManager downloadManager =
new DownloadManager(
context,
getDatabaseProvider(context),
getDownloadCache(context),
factory,
Executors.newFixedThreadPool(/* nThreads= */ 6));
https://developer.android.com/guide/topics/media/exoplayer/customization#customizing_server_interactions https://developer.android.com/reference/androidx/media3/datasource/ResolvingDataSource
@marcbaechinger We are creating DataSource.Factory and downloadManager only once for all downloads. May you plls elaborate how can we set the headers when the download starts and change the data spec accordingly.
Here is our code snippet
downloadManager = DownloadManager(
context,
databaseProvider,
downloadCache,
dataSourceFactory,
downloadExecutor
)
After setting downloadManager for DownloadService we are calling below api
DownloadService.sendAddDownload(
context,
service,
downloadRequest,
/* foreground= */ true
)
Please read the documentation links I sent above. I'm not going to repeat what is written there I'm afraid.
The Resolver
that you pass to the constructor of ResolvingDataSource
is called each time when a request is made. You can change the DataSpec
for each request.
We are using authenticated playback url. For fetching the segments we need to send some headers in requests. Same goes for content download and offline playback. For downloading the content we are making use of DownloadRequest class.
Proposed solution
Can DownloadRequest class be made open for extension. So that we can make our custom requests like adding headers or request parameters map etc.