shaka-player icon indicating copy to clipboard operation
shaka-player copied to clipboard

How to display a side loaded text track by default when using chromecast?

Open sonicd300 opened this issue 3 years ago • 1 comments

Have you read the Tutorials? yes

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

What version of Shaka Player are you using? 3.0.10

Please ask your question I have side loaded text tracks which load/render properly during playback in a browser, but these aren't showing up by default when casting, instead it's turning the caption selector to its off state, if i manually select a track then gets displayed.

The text tracks are being loaded after the player had fired the loaded event, using addTextTrackAsync and awaiting that promise (side note: sometimes even if it's awaited it doesn't return the track), then selected and its visibility set to true.

Is there anything in particular that needs to happen to display side loaded text tracks by default when casting?

sonicd300 avatar Apr 26 '21 23:04 sonicd300

That makes sense. The way the current Cast API works, it transmits the manifest URL to the device, where playback then starts and seeks to the same position. The way addTextTrackAsync works is by inserting a synthetic track to the parsed manifest. This is not transmitted to the Cast device when you start casting.

It's reasonable for you to expect this to work, though. We should find a way to fix this. I'm going to reclassify this as a bug.

As for a fix, here's one suggestion: We could potentially track metadata about side-loaded tracks in the player, separately from the manifest, and transmit this to the Cast device when we start casting. I don't have any other ideas off-hand.

For now, though, you can work around this in the receiver by calling addTextTrackAsync again on the cast side. For example:

// Sender side code.

// If using our UI, this gets you the CastProxy object.
// If you're not using our UI, you created this object yourself.
const castProxy = video.ui.getControls().getCastProxy();

// Set "app data" for the asset.  This can be anything you can serialize over JSON.
// In this example, I'm sending most of the params of addTextTrackAsync.
// You can choose what you send, though.  Always use VTT?
// Hard-code the MIME type in your receiver if you like instead of sending it.
castProxy.setAppData({
  sideLoadedText: {
    uri: 'foo',
    language: 'es',
    kind: 'subtitle',
    mimeType: 'text/vtt',
  },
});
// Receiver-side code.
// Use the app data callback to get the data from the sender app.
const receiver = new shaka.cast.CastReceiver(
    video, player, (appData) => {
      if (appData.sideLoadedText) {
        // Use the app data to side-load the text track on the receiver side.
        player.addTextTrackAsync(
            appData.sideLoadedText.uri,
            appData.sideLoadedText.language,
            appData.sideLoadedText.kind,
            appData.sideLoadedText.mimeType);
      }
    });

joeyparrish avatar Oct 06 '21 20:10 joeyparrish

Since we want to do https://github.com/shaka-project/shaka-player/issues/4214 I'm going to close this issue.

avelad avatar Dec 04 '23 11:12 avelad