androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.73k stars 413 forks source link

New subtitle transcoding feature loads all subtitles when initialising #1721

Open TheBeastLT opened 2 months ago

TheBeastLT commented 2 months ago

Version

Media3 1.4.1

More version details

No response

Devices that reproduce the issue

Any device

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

With the version 1.4.1 the experimentalSetTextTrackTranscodingEnabled feature is enabled by default and it introduces behaviour that is not expected and was not there before. With it enabled the player loads each and every subtitle configuration that is defined for the MediaItem even if it is not selected. There can be uses cases where these subtitles configuration are remote urls and there can be many of them for different languages, so loading all of them when initialising the media item is not efficient and introduces delay when the item is played. Ideally only the selected subtitle should be transcoded, as was the behaviour before with remote urls - it would get downloaded only when it was selected.

Expected result

Not all subtitle configuration are loaded when MediaItem is initialized

Actual result

All subtitles configuration are loaded (and in case of remote urls - are downloaded)

Media

Any

Bug Report

icbaker commented 2 months ago

This is due to the new subtitle handling using ProgressiveMediaPeriod rather than SingleSampleMediaPeriod, and the different implementations of MediaPeriod.prepare these two classes have.

SingleSampleMediaPeriod does nothing in its prepare method:

https://github.com/androidx/media/blob/c35a9d62baec57118ea898e271ac66819399649b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/SingleSampleMediaPeriod.java#L102-L104

And only loads data inside continueLoading (which will only be called after the track has been selected):

https://github.com/androidx/media/blob/c35a9d62baec57118ea898e271ac66819399649b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/SingleSampleMediaPeriod.java#L149-L157

Whereas ProgressiveMediaPeriod, as a general purpose class for playing progressive media files (like MP4), needs to load data in prepare in order to determine what tracks are available:

https://github.com/androidx/media/blob/c35a9d62baec57118ea898e271ac66819399649b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ProgressiveMediaPeriod.java#L241-L245

I agree this is unexpected, it's an unintended side-effect of using ProgressiveMediaPeriod.

TheBeastLT commented 3 weeks ago

@icbaker Are there any intentions to change and fix this?

icbaker commented 3 weeks ago

Yes, I'm working on this at the moment.