thibauts / node-castv2-client

A Chromecast client based on the new (CASTV2) protocol
MIT License
649 stars 95 forks source link

VTT support for subtitle #5

Closed the-fine closed 10 years ago

the-fine commented 10 years ago

Is it possible to add VTT text track support? It is supported on the DefaultMediaReceiver

thibauts commented 10 years ago

Of course you can do it ! I'll gladly review your pull request and provide any help Le 16 août 2014 16:28, "the-fine" notifications@github.com a écrit :

Is it possible to add VTT text track support? It is supported on the DefaultMediaReceiver

— Reply to this email directly or view it on GitHub https://github.com/thibauts/node-castv2-client/issues/5.

SlashmanX commented 10 years ago

Any progress on this? Would love to see track support in this module

the-fine commented 10 years ago

totally forgot about this, don't think i have the knowledge to do this :(

thibauts commented 10 years ago

Good news, I got them working after a great deal of trial and error as I couldn't find exemple code or traffic to snoop on.

A minor update to the module is needed. Then I'll try to post exemple code here.

SlashmanX commented 10 years ago

That's brilliant news. Thank you very much

thibauts commented 10 years ago

The client as well as the core protocol module have been updated and pushed to npm. Please rerun an npm install in your projects to get the latest versions.

Here is exemple code to try VTT support :

var Client                = require('castv2-client').Client;
var DefaultMediaReceiver  = require('castv2-client').DefaultMediaReceiver;
var mdns                  = require('mdns');

var browser = mdns.createBrowser(mdns.tcp('googlecast'));

browser.on('serviceUp', function(service) {
  console.log('found device "%s" at %s:%d', service.name, service.addresses[0], service.port);
  ondeviceup(service.addresses[0]);
  browser.stop();
});

browser.start();

function ondeviceup(host) {

  var client = new Client();

  client.connect(host, function() {
    console.log('connected, launching app ...');

    client.launch(DefaultMediaReceiver, function(err, player) {
      var media = {
        contentId: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4',
        contentType: 'video/mp4',
        streamType: 'BUFFERED',

        // !!! VTT: Here additional tracks are specified, only VTT is currently supported by the DefaultMediaReceiver.
        tracks: [{
          trackId: 1,
          type: 'TEXT',
          trackContentId: 'https://raw.githubusercontent.com/googlecast/CastClosedCaptioning-chrome/master/captions_styled.vtt',
          trackContentType: 'text/vtt',
          name: 'English',
          language: 'en-US',
          subtype: 'SUBTITLES'
        }]

      };

      player.on('status', function(status) {
        console.log('status broadcast playerState=%s', status.playerState);
      });

      console.log('app "%s" launched, loading media %s ...', player.session.displayName, media.contentId);

      // !!! VTT: You have to tell the Chromecast which trackIds to play with activetrackIds.
      player.load(media, { autoplay: true, activeTrackIds: [1] }, function(err, status) {
        if(err) {
          client.close();
          console.log(err);
          return;
        }
        console.log('media loaded playerState=%s', status.playerState);
      });

    });

  });

  client.on('error', function(err) {
    console.log('Error: %s', err.message);
    client.close();
  });

}

Check the comments to see how it works. Note that the server(s) delivering BOTH the video stream and the VTT file have to be CORS enabled. The video and the subtitles can come from a different server/host/domain though.

Tell me how it goes for you so I can close the issue if everything is OK.

SlashmanX commented 10 years ago

Brilliant work. I was actually super close to doing exactly what you did on the module last night, but I just gave up.

I'll give this a try tonight

thibauts commented 10 years ago

I can understand your frustration as there is no way to know if you're getting close to the goal until every single param falls exactly into place ...

Let me know how things go. Anyway there is still work left on subtitle styling, but I think it will be much easier to tinker with it following the API docs.

SlashmanX commented 10 years ago

Works absolutely perfectly. Great work

thibauts commented 10 years ago

Definitely works as expected, closing !

guerrerocarlos commented 10 years ago

Hello, Making some tests again and executing that same example script it does stream the movie/mp4 but for some reason it doesn't show the subtitles. Am I the only one with this problem?

thibauts commented 10 years ago

The github server no longer mirrors the origin header. It definitely works with a properly configured server.

nickdima commented 10 years ago

@thibauts do you know how the captions can be styled? For a bigger font size for example. In the example vtt there are some css classes used but how do we provide the css?

thibauts commented 10 years ago

I lack material to implement it for now. I'm quite busy for the weeks to come and may have a look when I have more free time. I opened an issue here. I will update its content soon to describe what I need to progress faster on this feature, in case you want to help.