jwplayer / jwplayer-react-native

MIT License
14 stars 4 forks source link

[BUG] Enabling captions to show by default is not working #29

Open mrstebo opened 2 weeks ago

mrstebo commented 2 weeks ago

Describe the bug I am trying to implement a feature that involves remembering the saved close caption preferences across videos in our app. I have used the setCurrentCaptions function, but it doesn't appear to be doing anything.

At the minute I have it hooked up to the onPlaylistItem event so that I know that the playlist item is ready to play, and that we have fetched the caption tracks. The video I have has a single caption track, and I have called this.playerRef.current.setCurrentCaptions(1) for it to automatically enable them. I am setting it to 1 as per the description in the documentation from the legacy repo here:

Turns off captions when argument is 0. Setting argument to another integer, sets captions to track at playlistItem.tracks[integer - 1]

Is this an issue, or am I doing something incorrectly?

To Reproduce Use the Example application as reference material and a starting place to reproduce any bugs.

Steps to reproduce the behavior:

  1. Load a playlist item that has captions
  2. Call the setCurrentCaptions function (currently in onPlaylistItem)
  3. See that the loaded video does not have the captions enabled

Expected behavior After calling setCurrentCaptions(1) I expect it to use the first caption track from the playlist item.

Screenshots / Visual evidence If applicable, add screenshots or recordings to help explain your problem. (Required if reproduction is not 100% reliable)

Desktop (please complete the following information): System: OS: macOS 14.4.1 CPU: (10) arm64 Apple M1 Pro Memory: 478.98 MB / 32.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.12.2 path: ~/.nvm/versions/node/v20.12.2/bin/node Yarn: version: 4.0.2 path: /opt/homebrew/bin/yarn npm: version: 10.5.0 path: ~/.nvm/versions/node/v20.12.2/bin/npm Watchman: Not Found Managers: CocoaPods: version: 1.15.2 path: /Users/stevenatkinson/.rbenv/shims/pod SDKs: iOS SDK: Platforms:

Device(s) affected I have seen this on the latest Android and iOS versions

Additional context Add any other context about the problem here.

Jmilham21 commented 1 week ago

@mrstebo, calling setCurrentCaptions in the onPlaylistItem will not work. On both platforms, you must wait for the player to finalize the setup before making this call. If you do this in the onPlaylistItem event, the call will most likely be ignored.

Something important to note here is this should work out of the box by the SDKs when using playlists in a single-player object. The SDK should retain the caption selection between playlist items. So if the user selects caption track 1 on playlist item 1, when playlist item 2 loads, we attempt to use caption track 1 (if the label matches).

We don't expose the best event to do this with (firstFrame for Android and didFinishLoadingWithTime on iOS) manually. I'm going to use this issue to expose a callback named onLoaded that will act as the onFirstFrame event used on our web player and Android SDK (and the same as didFinishLoadingWithTime on iOS). This will be the best place to add the setCurrentCaptions call. This should allow you to set the captions as expected when a player is ready to accept the method call.