use of com.google.android.exoplayer2.metadata.emsg.EventMessage in project ExoPlayer by google.
the class EventMessageDecoderTest method testDecodeEventMessage.
public void testDecodeEventMessage() {
byte[] rawEmsgBody = new byte[] { // scheme_id_uri = "urn:test"
117, // scheme_id_uri = "urn:test"
114, // scheme_id_uri = "urn:test"
110, // scheme_id_uri = "urn:test"
58, // scheme_id_uri = "urn:test"
116, // scheme_id_uri = "urn:test"
101, // scheme_id_uri = "urn:test"
115, // scheme_id_uri = "urn:test"
116, // scheme_id_uri = "urn:test"
0, // value = "123"
49, // value = "123"
50, // value = "123"
51, // value = "123"
0, // timescale = 48000
0, // timescale = 48000
0, // timescale = 48000
-69, // timescale = 48000
-128, // presentation_time_delta (ignored) = 0
0, // presentation_time_delta (ignored) = 0
0, // presentation_time_delta (ignored) = 0
0, // presentation_time_delta (ignored) = 0
0, // event_duration = 144000
0, // event_duration = 144000
2, // event_duration = 144000
50, // event_duration = 144000
-128, // id = 1000403
0, // id = 1000403
15, // id = 1000403
67, // id = 1000403
-45, 0, 1, 2, 3, // message_data = {0, 1, 2, 3, 4}
4 };
EventMessageDecoder decoder = new EventMessageDecoder();
MetadataInputBuffer buffer = new MetadataInputBuffer();
buffer.data = ByteBuffer.allocate(rawEmsgBody.length).put(rawEmsgBody);
Metadata metadata = decoder.decode(buffer);
assertEquals(1, metadata.length());
EventMessage eventMessage = (EventMessage) metadata.get(0);
assertEquals("urn:test", eventMessage.schemeIdUri);
assertEquals("123", eventMessage.value);
assertEquals(3000, eventMessage.durationMs);
assertEquals(1000403, eventMessage.id);
MoreAsserts.assertEquals(new byte[] { 0, 1, 2, 3, 4 }, eventMessage.messageData);
}
use of com.google.android.exoplayer2.metadata.emsg.EventMessage in project ExoPlayer by google.
the class EventMessageDecoder method decode.
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = inputBuffer.data;
byte[] data = buffer.array();
int size = buffer.limit();
ParsableByteArray emsgData = new ParsableByteArray(data, size);
String schemeIdUri = emsgData.readNullTerminatedString();
String value = emsgData.readNullTerminatedString();
long timescale = emsgData.readUnsignedInt();
// presentation_time_delta
emsgData.skipBytes(4);
long durationMs = (emsgData.readUnsignedInt() * 1000) / timescale;
long id = emsgData.readUnsignedInt();
byte[] messageData = Arrays.copyOfRange(data, emsgData.getPosition(), size);
return new Metadata(new EventMessage(schemeIdUri, value, durationMs, id, messageData));
}
use of com.google.android.exoplayer2.metadata.emsg.EventMessage in project ExoPlayer by google.
the class EventLogger method printMetadata.
private void printMetadata(Metadata metadata, String prefix) {
for (int i = 0; i < metadata.length(); i++) {
Metadata.Entry entry = metadata.get(i);
if (entry instanceof TextInformationFrame) {
TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id, textInformationFrame.value));
} else if (entry instanceof UrlLinkFrame) {
UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
} else if (entry instanceof PrivFrame) {
PrivFrame privFrame = (PrivFrame) entry;
Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
} else if (entry instanceof GeobFrame) {
GeobFrame geobFrame = (GeobFrame) entry;
Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s", geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
} else if (entry instanceof ApicFrame) {
ApicFrame apicFrame = (ApicFrame) entry;
Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s", apicFrame.id, apicFrame.mimeType, apicFrame.description));
} else if (entry instanceof CommentFrame) {
CommentFrame commentFrame = (CommentFrame) entry;
Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id, commentFrame.language, commentFrame.description));
} else if (entry instanceof Id3Frame) {
Id3Frame id3Frame = (Id3Frame) entry;
Log.d(TAG, prefix + String.format("%s", id3Frame.id));
} else if (entry instanceof EventMessage) {
EventMessage eventMessage = (EventMessage) entry;
Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s", eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
}
}
}
Aggregations