Hello all,
I am looking for a way to dynamically inject arbitrary metadata (for use as cue point) into a live stream and then get the metadata back in JWPlayer in different browsers (for both RTMP and HLS). After reading through various articles on this forum, I tried the following two methods as part of a HTTPProvider but neither of them works.
Try 1.
private boolean injectMetaData(IMediaStream stream, String payload) {
if (stream != null) {
AMFDataObj amfData = new AMFDataObj();
amfData.put("payload", payload);
stream.sendDirect("payload", amfData);
return true;
}
return false;
}
Try 2.
private boolean injectMetaData(IMediaStream stream, String payload) {
if (stream != null) {
AMFDataList amfList = new AMFDataList();
amfList.add(new AMFDataItem("@setDataFrame"));
amfList.add(new AMFDataItem("onMetaData"));
AMFDataMixedArray metaData = new AMFDataMixedArray();
metaData.put("payload", payload);
amfList.add(metaData);
synchronized(stream) {
byte[] dataData = amfList.serialize();
int size = dataData.length;
long timecode = Math.max(stream.getAudioTC(), stream.getVideoTC());
stream.setDataTC(timecode);
stream.setDataSize(size);
stream.startDataPacket();
stream.addDataData(dataData, 0, size);
}
return true;
}
return false;
}
The calls to the HTTPProvider completed successfully in both cases, but when trying to get the metadata back in JWPlayer in the browser, the custom metadata never showed up.
Here is how I am getting the metadata with JWPlayer:
jwplayer('player').on('meta', function(evt) {
console.log(evt.metadata);
};
What would be the correct way of doing this?
Thanks,
- Derrick