thibauts / node-castv2-client

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

Keeping track of media position #59

Open Rainnwind opened 7 years ago

Rainnwind commented 7 years ago

Hi.

I'm trying to keep track of the position of the played media on the chrome cast but I can't seem to find the proper event to listen on and alternatively I can't see to find a way to extract the position of the media.

Help needed :)

thibauts commented 7 years ago

Have you tried subscribing to status updates or calling getStatus ?

Rainnwind commented 7 years ago

Below is what I've tried with a subscription on status but it only fires when media status changes from IDLE to BUFFERED etc - is this expected behavior?

getStatus on the other hand works like a charm and I'll be using that for now :)

function castVideo(host: string, video: { source: string; type: string; }) {
  var client = new Client();
  var interval;
  client.connect(host, function () {
  client.launch(DefaultMediaReceiver, function (err, player) {
    var media = {
      contentId: video.source,
      contentType: video.type,
      streamType: 'BUFFERED',
      metadata: {
        type: 0,
        metadataType: 0,
        title: "..."
      }
    };
    player.on("status", function (status) {
      console.log(status);
    });
    player.load(media, { autoplay: true }, function (err, status) {
      ...
    });
  });
});