Search code examples
google-castchromecastsmooth-streamingclosed-captionsttml

ChromeCast TTML Closed Captioning with Smooth Streaming and PlayReady


Hy!

I would like to create an application which supports TTML typed closed captions.

My ism/manifest file contains the TTML based closed caption, I would like to ask how can I use it?

I found this site, https://developers.google.com/cast/docs/player where they described the following:

Segmented TTML & WebVTT

Use Segmented TTML for Smooth Streaming and WebVTT - Web Video Text Tracks for HLS.

To enable:

protocol_.enableStream(streamIndex, true); player_.enableCaptions(true);

But I can't find an example for my problem. Do I have to enable this after creating my host at the receiver side? Are there any sample app for this?

UPDATE #1

Here's my code:

  window.onload = function() {

  var mediaElement = document.getElementById('video'); //video is a html video tag

  var mediamanager = new cast.receiver.MediaManager(mediaElement);

  var url = "http://playready.directtaps.net/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/Manifest";  //Just a sample URL

  var host = new cast.player.api.Host({ 'mediaElement': mediaElement, 'url': url });

  window.player = new cast.player.api.Player(host);

  protocol = cast.player.api.CreateSmoothStreamingProtocol(host);

  var initStart = 0;

  window.player.load(protocol, initStart);

  mediamanager.loadedmetadata = function(loadinfo) {
          //onMetadataLoaded fired, set the caption
  }


  }

It doesn't work. So I decided to get the streams:

  var streamCount = protocol.getStreamCount();

And streamCount contains 0. The manifest contains the closed caption, should I use something else, not the getStreamCount()?

Thank you very much!


Solution

  • The correct approach is to listen for metadataloaded event. Once that event is fired, then you are good to get the stream count, but don't do that before that event is fired. Then you can enable the stream for the index that you want (for the language that you want, in case you have multiple ones) and then enable caption. If you want to change language, you first need to disable caption and then select a different stream index and then enable it again.