doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.25k stars 1k forks source link

[Feature Request] WebVTT subtitles support #2248

Closed jamsch closed 4 months ago

jamsch commented 8 months ago

What is the need and use case of this feature?

This is a wild shot, but would it be feasible adding WebVTT support in RNTP? Nothing in the RN space seems to support the following features:

Describe the ideal solution

Describe alternatives you've considered

  1. Just rendering everything inside a web view. This is essentially what we're doing on our web app:
<audio src="https://website.com/path/to/audio.ogg">
    <track
      src="https://website.com/path/to/subtitles.webvtt"
      kind="subtitles"
      src-lang="en"
      label="English"
      default
    />
</audio>

<script>
  document.querySelector("audio > track").addEventListener("cuechange", (event) => {
    console.log("active subtitle: ", event.target?.track.activeCues[0]?.text);
  });
</script>
  1. On the mobile app, I'm instead parsing out the WebVTT file contents in JS, such as the following:
export type WebVTTCue = {
  startTime: number;
  endTime: number;
  text: string;
};

export function parseWebVTT(input: string): { cues: WebVTTCue[] }

// ...
const { cues } = parseWebVTT(`WEBVTT\n\n1\n00:00:00.960 --> 00:00:03.000\n....`);

And using a simple binary search to locate the current cue:

function getCurrentCue(cues: WebVTTCue[], timestamp: number): WebVTTCue | false

However the issue with this current approach is that I'm finding that the timestamps (at least with the expo-av lib at the moment) are extremely unreliable and can be seconds out of sync with the actual underlying audio progress (even with no JS frame loss + 250ms reporting intervals).

Additional context

After experimenting with integrating WebVTT in Android Media3 ExoPlayer (using Expo Native Modules) about a year ago on this issue, I managed to get it working pretty good, however the solution was extremely hacky (due to my limited knowledge of the Android ecosystem) and I haven't yet tried integrating it on a mature AV project such as this one, or expo-av.

How I can Help

I'll likely have some free time soon to work on this again for Android and iOS, however my efforts will be in integrating this feature in a simple standalone player in a separate repo, just so that I can get a proof-of-concept out. I have no expertise in Kotlin/Swift so there'll need to be an experienced native developer to be able to integrate it in to this library.

lovegaoshi commented 7 months ago

this is a music library though, this is more relevant for the RN-video community (and is being worked on): https://github.com/react-native-video/react-native-video/pull/3541 isnt .lrc more relevant for music? and there are solutions for this RNTP really just plays music in the background, wont and shouldnt give a webview

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 4 months ago

This issue was closed because it has been stalled for 7 days with no activity.