Change External Subtitle Position on Exoplayer

See original GitHub issue

[REQUIRED] Searched documentation and issues

Checked Subtitle view: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/SubtitleView.html

[REQUIRED] Question

I want to change the subtitle position so for that i am using the following apis on Exoplayerview, exoPlayerSubtitleView.setBottomPaddingFraction(); exoPlayerSubtitleView.setPadding(); Set padding is on View class and i am using that api.

My question is that is it the correct approach to move the position of subtitleview anywhere on the player screen because setBottomPaddingFraction helps me to move up and padding right and left gives me possibility to move right and left; I am keeping top and bottom as Zero values.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
icbakercommented, Apr 16, 2020

Most subtitle formats can specify for each cue where in the viewport it should be drawn. The SubtitleView is transparent and exactly overlaid on the video viewport. The SubtitleView can position the cue text (or image) anywhere within itself, as specified by the positioning information from the subtitle source data.

In some cases, the position isn’t specified in the source data . This is usually indicated by Cue.DIMEN_UNSET values for Cue.line and/or Cue.position. In that case SubtitleView decides to draw the cue in a ‘default’ position, which is bottom-center. The SubtitleView#setBottomPaddingFraction() method can change the vertical position of these cues (and specifically only the cues with no explicit positioning info from the source data). There’s currently no way to configure the horizontal position of this ‘default’.

Do you want to position all cues in a fixed location, or only those that don’t carry their own positioning info?

You can achieve either by subclassing PlayerView and mutating the Cue objects in onCues() before passing them to super.onCues(). You’ll want to change the line and position fields (and possibly lineAnchor, lineType and positionAnchor too). If you only want to move ‘default positioned’ cues, then only change a field if it’s set to Cue.DIMEN_UNSET.

1reaction
icbakercommented, Apr 23, 2020

Thanks for the sample project - I think I know what’s going on.

The subtitles in the stream you provided are WebVTT and don’t explicitly set the size property (i.e. width for horizontal text). The WebVTT spec tells us to default to size=100% in this case (step 3 here: https://www.w3.org/TR/webvtt1/#processing-cue-settings).

Additionally the cues all have alignment=middle (i.e. centre the text inside the cue box).

So since you pass the Cue size straight through without modifying it, the cue box will always be spanning all the way to the right hand edge of the screen (because as you adjust position and positionAnchor, the size will be shrunk just enough to avoid going out-of-bounds (i.e. > 100%)).

And then since you also pass alignment straight through, you’re only able to position cues in the middle of a box that spans all the way to the right hand edge of the screen. This makes it impossible to ever get cues into the left hand portion of the screen.

You should be able to fix this by modifying either size or alignment or both. I was able to get cues showing up on the left with your sample app by passing Layout.Alignment.ALIGN_NORMAL instead of cues.get(0).textAlignment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change ExoPlayer subtitle position in android?
I'm show subtitle with exoPlayer in my android application. Now I want change position of subtitle from bottom of the screen to the...
Read more >
Exoplayer Subtitles - Top of Screen : r/SynclerApp - Reddit
Anyone have an issue where subtitles have moved to the top of Exoplayer, Can't find a way to move it to bottom, using...
Read more >
Android Question change position subtitle in exoplayer - B4X
i'm try to change the position subtitle in exoplayer. search and find setBottomPaddingFraction in exoplayer. how can to use this void?
Read more >
ExoPlayer in Android with Example - GeeksforGeeks
ExoPlayer is a media player library that provides a way to play audio and video with lots of customization in it. It is...
Read more >
RELEASENOTES.md - google/ExoPlayer - Sourcegraph
Ensure that changing the ShuffleOrder with ExoPlayer. ... to true so that errors loading external subtitle files do not cause playback to fail...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found