fix(android): merge sideloaded subtitle tracks via MergingMediaSource; guard PiP activity lookup#4906
Open
WithakErik wants to merge 2 commits into
Conversation
… lookup ProgressiveMediaSource.Factory (and HLS/DASH variants) silently ignore MediaItem.SubtitleConfiguration entries, so external subtitle/caption files never appeared in MappedTrackInfo or responded to setSelectedTextTrack. Fix: after the primary MediaSource is built, detect any SubtitleConfiguration entries on the MediaItem, create a dedicated ProgressiveMediaSource for each using SubtitleExtractor, and merge them all with MergingMediaSource. This makes sideloaded tracks selectable exactly like embedded tracks. Related: findActivity() previously threw IllegalStateException when the ComponentActivity wasn't reachable through the ContextWrapper chain — a condition that arises when PiP lifecycle events fire after the subtitle MergingMediaSource changes the ExoPlayer session state. Make it return null with a ThemedReactContext.getCurrentActivity() fallback; update all call sites to handle null gracefully. Also replace the deprecated context.currentActivity field with context.getCurrentActivity(). Fixes: external subtitles/captions not loading on Android (TheWidlarzGroup#4792, TheWidlarzGroup#4614)
…uard unsupported formats, preserve flags Three improvements over the initial subtitle fix: - Strip SubtitleConfigurations from the MediaItem before passing it to mediaSourceFactory so no factory variant (ProgressiveMediaSource, DefaultMediaSourceFactory, or plugin overrides) can create its own legacy subtitle sources alongside our MergingMediaSource. Prevents double-processing and the Media3 1.8 'Legacy decoding is disabled' crash that occurs when both paths are active. - Check subtitleParserFactory.supportsFormat() before calling create(). Previously an unknown mimeType would throw IllegalArgumentException at source creation time, killing playback entirely; now we log a warning and skip the unsupported track, matching DefaultMediaSourceFactory's behavior. - Carry selectionFlags and roleFlags from SubtitleConfiguration onto the rebuilt Format so default/forced-caption auto-selection and preferred- role selection continue to work correctly.
Author
|
Updated with three hardening improvements (based on additional code review):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
External subtitle/caption files passed via
textTracksnever appeared on Android. Two related bugs:Bug 1 — Subtitles silently ignored
ProgressiveMediaSource.Factory(and the HLS/DASH variants) ignoreMediaItem.SubtitleConfigurationentries entirely. Subtitles set viasetSubtitleConfigurationsare attached to theMediaItembut never loaded intoMappedTrackInfo, sosetSelectedTextTrackhas nothing to select.Reported in #4792 and #4614.
Bug 2 — PiP crash after subtitle change
findActivity()threwIllegalStateExceptionwhen theComponentActivitywasn't reachable through theContextWrapperchain. This surface became more likely after the subtitle fix changes ExoPlayer's internal session/lifecycle state viaMergingMediaSource.Fix
Subtitle fix (
ReactExoplayerView.java)After the primary
MediaSourceis built, check forSubtitleConfigurationentries on theMediaItem. For each one, create a dedicatedProgressiveMediaSourcebacked by aSubtitleExtractor, then merge all sources withMergingMediaSource. This makes sideloaded tracks appear inMappedTrackInfoand respond tosetSelectedTextTrackexactly like embedded tracks.PiP fix (
PictureInPictureUtil.kt)findActivity()now returnsComponentActivity?instead of throwing, with aThemedReactContext.getCurrentActivity()fallbackcontext.currentActivityfield withcontext.getCurrentActivity()Testing
Verified on a physical Android device (arm64-v8a) with external
.vttsubtitle files. Subtitles now load and are selectable. PiP entry/exit no longer crashes after subtitles are active.Closes #4792
Related: #4614