Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I decode id3 metadata in a chromecast receiver app?

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

like image 869
Mike Mintz Avatar asked Oct 19 '22 02:10

Mike Mintz


1 Answers

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;
  }
  ...
};
like image 61
Mike Mintz Avatar answered Dec 28 '22 10:12

Mike Mintz