-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/android subtitle event #3566
Feat/android subtitle event #3566
Conversation
Thank you again for the PR, the onCue part looks OK for me, but the showSubtitles shall not be added in subtitlesStyles. To disable display of subtitle, you should selectedTextTrack={'disabled'} Can you either remove showSubtitles or better rename it to opacity ;) |
You need also to fix conflict please ! |
Thank you for the time you've taken to review the PR and for your constructive feedback! After considering your comments regarding the subtitleLayout = new SubtitleView(context);
public void setSubtitleStyle(SubtitleStyle style) {
subtitleLayout.setUserDefaultStyle();
subtitleLayout.setUserDefaultTextSize();
if (style.getFontSize() > 0) {
subtitleLayout.setFixedTextSize(TypedValue.COMPLEX_UNIT_SP, style.getFontSize());
}
subtitleLayout.setPadding(style.getPaddingLeft(), style.getPaddingTop(), style.getPaddingRight(), style.getPaddingBottom());
subtitleLayout.setVisibility(style.getShowSubtitles() ? View.VISIBLE : View.GONE);
} This approach was inspired by the CSS display property, which controls visibility in a somewhat similar fashion. However, I recognize that the analogy isn't perfect, as detailed in the display docs. Addressing the
|
6cb55e0
to
c69e21e
Compare
Fixed the conflict :) |
|
Going to resolve these new conflicts, then remove the |
- Added `showSubtitles` flag to `props.md` to control subtitle display post `selectedTextTrack` configuration. - Updated `events.md` to document support for `onTextTrackDataChanged` event on Android.
chore: revert auto formatting. chore: revert auto formatting. chore: revert auto formatting.
events.md deleted; moved to events.mdx updated props.mdx to remove showSubtitles.
Removed per feedback from https://github.com/react-native-video/react-native-video/pull/3566/files will create a feature issue to discuss proper implementation. updated new events.mdx documentation. removed the note related to showSubtitles use from props.mdx removed type for showSubtitles chore: remove showSubtitle type from VideoNativeComponent
c69e21e
to
53be0c4
Compare
New conflicts resolved, removed the showSubtitles flag under styles, and re-tested in example :) |
@@ -1521,6 +1522,13 @@ public void onMetadata(@NonNull Metadata metadata) { | |||
eventEmitter.timedMetadata(metadataArray); | |||
} | |||
|
|||
public void onCues(CueGroup cueGroup) { | |||
if (!cueGroup.cues.isEmpty() && cueGroup.cues.get(0).text != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you think adding following safety check would be a good idea ?
if (!cueGroup.cues.isEmpty() && cueGroup.cues.get(0).text != null) { | |
if (cueGroup != null && !cueGroup.cues != null && !cueGroup.cues.isEmpty() && cueGroup.cues.get(0).text != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with adding these safety checks; they’re a good idea. I think there might be a small typo in the suggestion, though. Shouldn’t !cueGroup.cues != null
be cueGroup.cues != null
?
if (cueGroup != null && cueGroup.cues != null && !cueGroup.cues.isEmpty() && cueGroup.cues.get(0).text != null) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with adding these safety checks; they’re a good idea. I think there might be a small typo in the suggestion, though. Shouldn’t
!cueGroup.cues != null
becueGroup.cues != null
?if (cueGroup != null && cueGroup.cues != null && !cueGroup.cues.isEmpty() && cueGroup.cues.get(0).text != null) {
And I am not sure it passes the linter 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK good, let's merge like this so !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet, that sounds awesome 🤩
📝 Summary
This PR is the android implementation for accessing subtitle content via the
onTextTrackDataChanged
method . Theios
counterpart can be found here . The functionality leverages theonCues
method from thePlayer.Listener
. It adds the capability for users to control the display of subtitles through thesubtitleStyles
prop. It has been emphasized in the documentation that, theshowSubtitles
flag is to be used in conjunction with theselectedTextTrack
prop; thus, allowing for selectingtextTracks
but deciding if you want to display them or not.Motivation
Building on our previous efforts to improve user engagement with HLS VOD sports content through the
onTextTrackDataChanged
event handler, we've identified a new opportunity to enhance flexibility and control over subtitle display on Android. The introduction of theshowSubtitles
boolean prop is a direct response to the limitations observed in handling subtitle data. Previously, selecting tracks via theselectedTextTrack
method would automatically display subtitles, offering no option to hide them while still accessing their data for other purposes, such as displaying game scores or other contextual information dynamically. This limitation was particularly noticeable when attempting to offer a clean, unobstructed view of the video content while simultaneously making use of subtitle data for enhancing viewer experience. By enabling the ability to hide subtitles even when they are selected, we empower developers to access and use subtitle data viaonCues
on Android (andlegibleOutput
on iOS) without forcing the display of subtitles on the screen.Changes
showSubtitles
to control the visibility of subtitles.onTextTrackDataChanged
event for Android, aligning with the existing iOS implementation for consistency.📄 Documentation
Test plan
✅ Tested in example app with
sintel with subtitles
URIApply the following changes in the basic app:
Comment out this line; due to textTracks being undefined, I believe it has to do with how data.textTracks is being set; but, I didn't want to address that on this PR as its a separate issue.
Comment out this line for the app to build(is there a permanent fix for this 🤔):
Demo:
demo_subtitles.mp4
If you explicitly want to set them ( the default is visible):
Proof that they default to visible without having to set them:
What happens if you set
showSubtitles
but dont select a track?They won't show :), this is explained in the documentation as well. This control is added for display, not setting them or not.