Checked Subtitle view: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/SubtitleView.html
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.
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.
Thanks @icbaker , will check your inputs.
Hi @icbaker,
We tried your suggestion and it is working in someway. Means we are able to move the subtitle, up/down and only on the right side of the player. We are not able to move it on the left side.
We tried touching the line, lineType, lineAnchor and position, positionAnchor. We could move it on percentage(fractional) basis using line, lineType vertically and by using position, positionAnchor only towards right. So we could move anywhere only right side of the screen.
But still not able to move left side. What are we missing? Can you please suggest ?
With following snippet we can move it in the center of right half.
Cue newCue = new Cue(text,
cues.get(0).textAlignment,
0.5F,
Cue.LINE_TYPE_FRACTION,
ANCHOR_TYPE_START,
0.5F,
ANCHOR_TYPE_START,
cues.get(0).size);
Sounds strange - it sounds like maybe the SubtitleView isn't the full width of the video viewport for some reason. You might be able to connect the Android Studio layout inspector and see if anything odd is going on.
Have you made these PlayerView changes in your own app or in a version of the demo app? You could try making the same changes in the demo app and see if you see the same behaviour or not.
If it's in your own app, it's hard for us to debug without a minimal reproducible example that demonstrates the problem in a way that we build locally. This could be an Android Studio project on GitHub, or zipped up and sent to dev.[email protected] (with subject "Issue #1234").
Hi @icbaker, I have shared the modified exoplayer code on the mentioned email id with subject Issue #7243. I have mentioned which media to test. The media has subtitles. The code is from release-v2 branch.
I checked the same snippet in PlayerView in onCues, i found the same behavior.
One more thing, i can see in dev-v2, this month there are couple of changes where all the cue's constructors have been marked deprecated and Builder has been introduced.
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.
Will try your inputs and will let you know. Anyways thanks a lot for the details.
Thanks @icbaker , you solution and suggestions worked.
Most helpful comment
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_UNSETvalues forCue.lineand/orCue.position. In that case SubtitleView decides to draw the cue in a 'default' position, which is bottom-center. TheSubtitleView#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
PlayerViewand mutating the Cue objects inonCues()before passing them tosuper.onCues(). You'll want to change thelineandpositionfields (and possiblylineAnchor,lineTypeandpositionAnchortoo). If you only want to move 'default positioned' cues, then only change a field if it's set toCue.DIMEN_UNSET.