5

Using Host.processMetadata() to get ID3 tags in the video stream. It says that this comes as a Uint8Array but I can't figure out how to decode this properly. I am using:

new TextDecoder("utf-8").decode(data);

However that is not decoding the data properly. How do I get the data?

Reference: https://developers.google.com/cast/docs/reference/player/cast.player.api.Host#processMetadata

Brad
  • 159,648
  • 54
  • 349
  • 530
Mike Mintz
  • 273
  • 1
  • 11

2 Answers2

2

Here is how I solved it (recommended by the folks at Google)

customReceiver.mediaHost.processMetadata = function (type, data, timestamp) {    
  var id3 = new TextDecoder("utf-8").decode(data.subarray(10));
  id3 = id3.replace(/\u0000/g, '');
  var id3Final;
  var id3Data = {
    type: 'meta',
    metadata: {}
  };
  if (id3.indexOf('TIT2') !== -1) {
    id3Final = id3.substring(5);
    id3Data.metadata.title = id3Final.substring(1);
    id3Data.metadata.TIT2 = id3Final;
  } else {
    id3Final = id3.substring(5);
    id3Data.metadata.TIT3 = id3Final;
  }
  ...
};
Mike Mintz
  • 273
  • 1
  • 11
1

I know this is late, but I ran into this same issue, and this is how I handled it to get TIT2 strings from the id3 tags:

// Receives and broadcasts TIT2 messages 
myCustomPlayer.CastPlayer.prototype.processMetadata_ = function(type, data, timestamp) {
  var id3String = String.fromCharCode.apply(null, data);
  if (type === 'ID3' && /TIT2/.test(id3String)) {
    this.someMessageBus_.broadcast(JSON.stringify({
      id3Tag: id3String.split('|')[1]
    }));
  }
}
Yowon Yoon
  • 11
  • 2