Skip to content

Text tracks with src= on Safari & UITextDisplayer are sometimes rendered natively. #8255

Closed
@matvp91

Description

@matvp91

Have you read the FAQ and checked for duplicate open issues?
Yes

If the problem is related to FairPlay, have you read the tutorial?
Possibly, I tested plain HLS and wasn't able to reproduce.

What version of Shaka Player are you using?
v4.13.9

Can you reproduce the issue with our latest release version?
Yes

Can you reproduce the issue with the latest code from main?
Yes

Are you using the demo app or your own custom app?
Both demo app and custom app

If custom app, can you reproduce the issue using our demo app?
Yes

What browser and OS are you using?
macOS, Safari 15 (least supported version) and Safari 18 (latest)

For embedded devices (smart TVs, etc.), what model and firmware version are you using?
Not applicable to embedded devices as this concerns src= with potentially FairPlay.

What are the manifest and license server URIs?
N/A

What configuration are you using? What is the output of player.getNonDefaultConfiguration()?

{
  "drm": {
    "servers": {
      "com.apple.fps.1_0": "https://lic.drmtoday.com/license-server-fairplay/"
    },
    "advanced": {
      "com.apple.fps.1_0": {
        "distinctiveIdentifierRequired": false,
        "persistentStateRequired": false,
        "sessionType": "",
        "serverCertificate": "__REDACTED___",
      }
    }
  },
  "streaming": {
    "preferNativeHls": true
  },
  "preferredAudioLanguage": "en-GB"
}

What did you do?
For reference, this concerns text tracks defined as following:

// ...
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitles",NAME="Nederlands",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="nld",URI="b7a60a46cb6843eca600ba2269c237a1/05f3521ac9034f81bcbb983f18ca125a/index_9_0.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitles",NAME="Nederlands T888",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="nld",CHARACTERISTICS="public.accessibility.describes-spoken-dialog,public.accessibility.describes-music-and-sound",URI="b7a60a46cb6843eca600ba2269c237a1/05f3521ac9034f81bcbb983f18ca125a/index_10_0.m3u8"

In the demo app, upon starting, Safari renders the text tracks natively. Video is excluded due to FairPlay preventing a screenshot.

Image

There's a mismatch between the default selected text track by Safari and the listeners we appended to pass cues to UiTextDisplayer.

Image

What did you expect to happen?
Have UiTextDisplayer render the cue's instead of Safari natively.

What actually happened?
There appears to be a subtle timing issue where we sync state with what Safari initially selected. Calling enableNativeTrack_ too early causes Safari to sometimes (this doesn't always happen unfortunately) select the next AUTOSELECT=YES track by itself.

shaka-player/lib/player.js

Lines 3226 to 3239 in 0361cee

let enabledNativeTrack = false;
for (const track of textTracks) {
if (track.mode !== 'disabled') {
if (!enabledNativeTrack) {
this.enableNativeTrack_(track);
enabledNativeTrack = true;
} else {
track.mode = 'disabled';
shaka.log.alwaysWarn(
'Found more than one enabled text track, disabling it',
track);
}
}
}

At first, I delayed enableNativeTrack_ by wrapping it in a timer and executing 250ms after. However, I don't think this is reliable, nor do I like a random timeout to circumvent browser behavior. I'm not aware of a way to instruct Safari to ignore AUTOSELECT signaled from the playlist.

I noticed that setting each disabled text track in src= mode to hidden before we handle our own logic (such as appending listeners for handling cues), makes Safari skip selecting the next default track. Likely because Safari looks at disabled text tracks and sets the first matching to showing. Due to the fact that they're all hidden besides potentially one showing (the one selected by Safari as default), we signalled we'd handle text tracks ourselves. It's a wild guess though.

if (shaka.util.Platform.isApple() && textTracks.length > 1 &&
    textTracks.some((track) => track.mode !== 'disabled')) {
  for (const track of textTracks) {
    if (track.mode === 'disabled') {
      track.mode = 'hidden';
    }
  }
}

// Calling this.enableNativeTrack_(track); after

I'll give this some more thought as I'm not convinced I won't bump into another odd Safari case. I'll provide a PR after.

Are you planning to send a PR to fix it?
Yes

Metadata

Metadata

Assignees

Labels

browser: SafariIssues affecting Safari or WebKit derivativespriority: P2Smaller impact or easy workaroundtype: bugSomething isn't working correctly

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions