-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MP4 download HttpDataSource #11120
Comments
After some more testing I found that Is it best practice to use different |
A |
I'm passing @Synchronized
fun getHttpDataSourceFactory(): HttpDataSource.Factory {
if(!DownloadUtil::httpDataSourceFactory.isInitialized) {
httpDataSourceFactory = OkHttpDataSource.Factory(OkHttpClient.Builder().build())
}
return httpDataSourceFactory
}
@Synchronized
private fun ensureDownloadManagerInitialized(context: Context) {
if(!DownloadUtil::downloadManager.isInitialized) {
downloadManager = DownloadManager(
context,
getDatabaseProvider(context),
getDownloadCache(context),
getHttpDataSourceFactory(),
Executors.newFixedThreadPool(6)
).apply {
maxParallelDownloads = 2
}
downloadTracker =
DownloadTracker(context, getHttpDataSourceFactory(), downloadManager)
}
} I have modified my ExoPlayer.Builder(this)
.setMediaSourceFactory(ProgressiveMediaSource.Factory(DownloadUtil.getHttpDataSourceFactory()))
.build()
.apply {
setMediaItem(mediaItem)
prepare()
} The download is still stuck when reading at the same time. Also note that this issue doesn't appear when using |
I'm confused by your updates. You said:
But then you said:
How can you be seeing the same |
You are totally right, I'm using Could the download be stuck because of public CacheDataSource createDataSourceForDownloading() {
return createDataSourceInternal(
upstreamDataSourceFactory != null ? upstreamDataSourceFactory.createDataSource() : null,
flags | FLAG_BLOCK_ON_CACHE,
C.PRIORITY_DOWNLOAD);
} |
I'm afraid we don't have capacity to provide 1:1 support for individual apps - if you believe there's a bug in the |
It is reproducible with the demo app, I've just added a download button inside the Step to reproduce:
You'll see the download is stuck at the beginning while you're on the |
Thanks, I'm able to reproduce what you're seeing. My suspicion is that this is due to OkHttp's connection pooling/re-use. Since the same I spotted this bit of the OkHttp docs that suggests this might only happen for HTTP/2 connections (emphasis mine):
Sure enough, I can make the download proceed while playback is paused by forcing OkHttp to use HTTP 1.1: OkHttpClient okHttpClient =
new OkHttpClient.Builder()
.protocols(ImmutableList.of(Protocol.HTTP_1_1))
.build();
httpDataSourceFactory = new OkHttpDataSource.Factory((Call.Factory) okHttpClient); I'm not sure what a better solution here is. It seems reasonable to request a resource twice from the same server (or even at the same URI) and leave one request open/pending/consumed while expecting the other to make progress - and I would expect OkHttp to support this, but it doesn't seem to. If you want this to work with OkHttp and HTTP/2 I suggest you ask on https://github.com/square/okhttp/issues (you can reference this issue as context of course). |
Thank you for your in-depth explanation, I was starting to guess the issue lied in OkHttpClient. I'll create an issue on okhttp side and hopes this can be fixed |
Looks like an issue already exists in media3 |
Closing because I think square/okhttp#7768 and androidx/media#188 adequately track this now. |
Fix here square/okhttp#7801 If anyone can test out the snapshot, instructions here square/okhttp#7768 (comment) , it well help give us confidence on the OkHttp fix. Likely in a 5 alpha, and then 4.12 a bit later. @icbaker I think androidx/media#188 is unrelated, while addressing that would also fix the symptoms of this issue, you should be able to keep streams open and complete downloads at the same time. |
Bug
I've been trying to download MP4 file via
OkHttpDataSource
but it downloads only the chunks that have been played by the player. The download process correctly with other DataSource such asDefaultHttpDataSource
andCronetDataSource
I have a repository which shows the issue: https://github.com/yoobi/exoplayer-kotlin/tree/issue/okhttp_download_mp4/downloadvideo
When using
OkHttpDataSource
to download HLS video there is no issue, but when it comes to MP4 you need to play the video to progress in the downloads.The text was updated successfully, but these errors were encountered: