Fix subtitles rendered outside the video in portrait mode - #1861
Open
hoyahozz wants to merge 1 commit into
Open
Conversation
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.
Cause
SubtitleViewusesfillMaxSize()as a sibling ofPlayerSurface. As a result, it is measured against the entire player, while only the video surface is resized withresizeWithContentScale.Media3 positions subtitle cues as a fraction of the subtitle view's height. For a letterboxed video, that fraction is therefore applied to the full screen rather than to the visible video area, causing subtitles to appear below the picture.
Cues with an embedded fractional size, such as SSA/ASS cues, are also scaled by the same incorrect ratio and become oversized. Plain SRT cues keep their expected size because the app applies an absolute text size.
The issue is primarily visible in portrait mode. In landscape, the video height usually matches the subtitle view height, so the incorrect measurement is not noticeable.
Media3's
PlayerViewavoids this by placingSubtitleViewinsideexo_content_frameinexo_player_view.xml.Fix
Measure the subtitle view against the visible video bounds instead of the entire player.
The calculated size uses the same
ContentScalebehavior as the video surface, but is clamped to the player bounds on each axis.The clamp is required because
resizeWithContentScaleallows content to overflow the container. That behavior is correct for the video surface, but not for subtitles.Without the clamp,
CROPproduced a subtitle view 4693 px wide on a 1080 px screen, causing both ends of the cue to render off-screen.HUNDRED_PERCENTcan overflow horizontally as well, so the clamp must be applied independently to both axes.Zoom, pan, and the Picture-in-Picture source rect remain applied only to the video surface. Subtitles therefore do not scale with pinch zoom, which preserves the existing behavior.
Before / after
Portrait mode, embedded ASS subtitles.