Skip to content
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

Feature/determine text track kind based on CHARACTERISTICS #4850

Conversation

lpommers
Copy link
Contributor

@lpommers lpommers commented Aug 15, 2022

This PR will...

will set the text track kind to either captions or subtitles based on CHARACTERISTICS attribute in the MediaPlaylist for the track.

Why is this Pull Request needed?

If a text tracks has CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog,public.accessibility.describes-music-and-sound, the native video element in Safari will set the kind property of the textTrack to captions instead of subtitles.

Are there any points in the code the reviewer needs to double check?

  1. I wasn't sure here if there was any MediaPlaylist information here to analyze to make the distinction between captions and subtitles when making a native text track.
    private createNativeTrack(trackName: string) {
    if (this.captionsTracks[trackName]) {
    return;
    }
    const { captionsProperties, captionsTracks, media } = this;
    const { label, languageCode } = captionsProperties[trackName];
    // Enable reuse of existing text track.
    const existingTrack = this.getExistingTrack(trackName);
    if (!existingTrack) {
    const textTrack = this.createTextTrack('captions', label, languageCode);
    if (textTrack) {
    // Set a special property on the track so we know it's managed by Hls.js
    textTrack[trackName] = true;
    captionsTracks[trackName] = textTrack;
    }
    } else {
    captionsTracks[trackName] = existingTrack;
    clearCurrentCues(captionsTracks[trackName]);
    sendAddTrackEvent(captionsTracks[trackName], media as HTMLMediaElement);
    }
    }
    .
  2. The same goes for a non-native textTrack. I wasn't sure if I should be adding CHARACTERISTICS information to captionsProperties or not.
    private createNonNativeTrack(trackName: string) {
    if (this.nonNativeCaptionsTracks[trackName]) {
    return;
    }
    // Create a list of a single track for the provider to consume
    const trackProperties: TrackProperties = this.captionsProperties[trackName];
    if (!trackProperties) {
    return;
    }
    const label = trackProperties.label as string;
    const track = {
    _id: trackName,
    label,
    kind: 'captions',
    default: trackProperties.media ? !!trackProperties.media.default : false,
    closedCaptions: trackProperties.media,
    };
    this.nonNativeCaptionsTracks[trackName] = track;
    this.hls.trigger(Events.NON_NATIVE_TEXT_TRACKS_FOUND, { tracks: [track] });
    }

Resolves issues:

Closes #2472

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@robwalch robwalch enabled auto-merge (squash) August 15, 2022 23:47
@robwalch robwalch added this to the 1.2.1 milestone Aug 15, 2022
@robwalch robwalch disabled auto-merge August 16, 2022 16:22
@robwalch robwalch merged commit 9e1a3aa into video-dev:master Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebVTT caption support
2 participants