-
-
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: Add ios support for accessing WebVTT Subtitle Content #3541
Feat: Add ios support for accessing WebVTT Subtitle Content #3541
Conversation
Push the parsing/formatting to the consumer side.
…Tracks added optional chaining for `return x?.selected` because tracks that don't have a track selected either by default or manually will return undefined and this can cause an error.
few comments, but looks good ! |
Thank you for the feedback 🙏🏽! I'll take a look at the |
Renamed the onSubtitleTracks event to onTextTrackDataChanged across the codebase to clearly indicate the callback's purpose: being called when the text track's data changes. This change is reflected in the events documentation, example usage in VideoPlayer.tsx, and the relevant iOS implementation files for consistency and clarity, in line with PR feedback.
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.
LGTM, Thank you very much 👍
Let's wait for @freeboub review (this may take some time, for what I know he's busy lately)
target could be confusing for users so we have removed it. using the delete operator instead of using {target,...eventData} as that would give an eslint error about unused vars.
Awesome, happy to help! Excited to get this merged in 😊 |
@KrzysztofMoch any other blockers I need to take care of to get this merged? 😅 |
No 😄 |
📝 Summary
This PR adds the capability to access and expose the content of subtitles within RN; but, currently only implements the
ios
portion. The core of this functionality leveragesAVFoundation framework's
AVPlayerItemLegibleOutput
, enabling the app to intercept subtitle data as attributed strings during video playback. This data is subsequently passed to do the RN layer through the newly introduced event,onSubtitleTracks
; thus, allowing components to reactively update based on thissubtitle
content.Motivation
Our motivation for integrating the onSubtitleTracks event handler with
react-native-video
is to enhance user engagement with HLS VODs of sports content. Utilizing WebVTT tracks, we aim to dynamically display game information like scores as overlays on the video, based on the playback position. This feature ensures viewers have access to contextual sports data as they navigate through the video, significantly improving their viewing experience by making it more informative and interactive. This implementation aligns with the capabilities of the WebVTT API, optimizing our app's use of text tracks for an enriched sports viewing experience.source
Changes
📲 iOS Implementation:
RCTPlayerObserver
class implementsAVPlayerItemLegibleOutputPushDelegate
to observe and handle subtitle tracks.legibleOutput
on the player item and set the current class as the delegate to manage legible output.legibleOutput
delegate method to capture subtitle data, processing it via thehandleLegibleOutput
method to extract and utilize subtitle strings.🌉 RN Bridge:
onSubtitleTracks
to facilitate event emission, enabling the RN layer to receive subtitle data.handleLegibleOutput
to handle attributed strings from subtitles, triggering theonSubtitleTracks
event with the subtitle text for consumption within RN components.🥳 RN Layer
onSubtitleTracks
property.Example:
📄 Docs
events.md
to include a description aligned with current standards.Test plan
✅ Tested in example app with
uri
included in this PRSet the tracks you want to use, for my demo I used the below; however,
SelectedTrackType.LANGUAGE
also works. For my actual use-case, we'll be usingTITLE
so I wanted to make sure that worked.Comment out this line; due to
textTracks
being undefined, I believe it has to do with howdata.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( I believe this is a known issue):
Demo of how it works:
demo.mp4