Search in sources :

Example 1 with Id3Decoder

use of com.google.android.exoplayer2.metadata.id3.Id3Decoder in project ExoPlayer by google.

the class Id3DecoderTest method testDecodeTxxxFrame.

public void testDecodeTxxxFrame() throws MetadataDecoderException {
    byte[] rawId3 = new byte[] { 73, 68, 51, 4, 0, 0, 0, 0, 0, 41, 84, 88, 88, 88, 0, 0, 0, 31, 0, 0, 3, 0, 109, 100, 105, 97, 108, 111, 103, 95, 86, 73, 78, 68, 73, 67, 79, 49, 53, 50, 55, 54, 54, 52, 95, 115, 116, 97, 114, 116, 0 };
    Id3Decoder decoder = new Id3Decoder();
    Metadata metadata = decoder.decode(rawId3, rawId3.length);
    assertEquals(1, metadata.length());
    TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
    assertEquals("TXXX", textInformationFrame.id);
    assertEquals("", textInformationFrame.description);
    assertEquals("mdialog_VINDICO1527664_start", textInformationFrame.value);
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 2 with Id3Decoder

use of com.google.android.exoplayer2.metadata.id3.Id3Decoder in project ExoPlayer by google.

the class Id3DecoderTest method testDecodeApicFrame.

public void testDecodeApicFrame() throws MetadataDecoderException {
    byte[] rawId3 = new byte[] { 73, 68, 51, 4, 0, 0, 0, 0, 0, 45, 65, 80, 73, 67, 0, 0, 0, 35, 0, 0, 3, 105, 109, 97, 103, 101, 47, 106, 112, 101, 103, 0, 16, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    Id3Decoder decoder = new Id3Decoder();
    Metadata metadata = decoder.decode(rawId3, rawId3.length);
    assertEquals(1, metadata.length());
    ApicFrame apicFrame = (ApicFrame) metadata.get(0);
    assertEquals("image/jpeg", apicFrame.mimeType);
    assertEquals(16, apicFrame.pictureType);
    assertEquals("Hello World", apicFrame.description);
    assertEquals(10, apicFrame.pictureData.length);
    MoreAsserts.assertEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, apicFrame.pictureData);
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 3 with Id3Decoder

use of com.google.android.exoplayer2.metadata.id3.Id3Decoder in project ExoPlayer by google.

the class Id3Peeker method peekId3Data.

/**
 * Peeks ID3 data from the input and parses the first ID3 tag.
 *
 * @param input The {@link ExtractorInput} from which data should be peeked.
 * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all
 *     frames.
 * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not
 *     present in the input.
 * @throws IOException If an error occurred peeking from the input.
 */
@Nullable
public Metadata peekId3Data(ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate) throws IOException {
    int peekedId3Bytes = 0;
    @Nullable Metadata metadata = null;
    while (true) {
        try {
            input.peekFully(scratch.getData(), /* offset= */
            0, Id3Decoder.ID3_HEADER_LENGTH);
        } catch (EOFException e) {
            // If input has less than ID3_HEADER_LENGTH, ignore the rest.
            break;
        }
        scratch.setPosition(0);
        if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) {
            // Not an ID3 tag.
            break;
        }
        // Skip major version, minor version and flags.
        scratch.skipBytes(3);
        int framesLength = scratch.readSynchSafeInt();
        int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength;
        if (metadata == null) {
            byte[] id3Data = new byte[tagLength];
            System.arraycopy(scratch.getData(), 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH);
            input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength);
            metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength);
        } else {
            input.advancePeekPosition(framesLength);
        }
        peekedId3Bytes += tagLength;
    }
    input.resetPeekPosition();
    input.advancePeekPosition(peekedId3Bytes);
    return metadata;
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) EOFException(java.io.EOFException) Id3Decoder(com.google.android.exoplayer2.metadata.id3.Id3Decoder) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Example 4 with Id3Decoder

use of com.google.android.exoplayer2.metadata.id3.Id3Decoder in project ExoPlayer by google.

the class Id3DecoderTest method decodeFailsIfArrayOffsetNonZero.

@Test
public void decodeFailsIfArrayOffsetNonZero() {
    Id3Decoder decoder = new Id3Decoder();
    MetadataInputBuffer buffer = createMetadataInputBuffer(createByteArray(1, 2, 3));
    buffer.data.position(1);
    buffer.data = buffer.data.slice();
    assertThrows(IllegalArgumentException.class, () -> decoder.decode(buffer));
}
Also used : MetadataInputBuffer(com.google.android.exoplayer2.metadata.MetadataInputBuffer) Test(org.junit.Test)

Example 5 with Id3Decoder

use of com.google.android.exoplayer2.metadata.id3.Id3Decoder in project ExoPlayer by google.

the class Id3DecoderTest method decodeFailsIfBufferHasNoArray.

@Test
public void decodeFailsIfBufferHasNoArray() {
    Id3Decoder decoder = new Id3Decoder();
    MetadataInputBuffer buffer = createMetadataInputBuffer(createByteArray(1, 2, 3));
    buffer.data = buffer.data.asReadOnlyBuffer();
    assertThrows(IllegalArgumentException.class, () -> decoder.decode(buffer));
}
Also used : MetadataInputBuffer(com.google.android.exoplayer2.metadata.MetadataInputBuffer) Test(org.junit.Test)

Aggregations

Metadata (com.google.android.exoplayer2.metadata.Metadata)13 Test (org.junit.Test)11 MetadataInputBuffer (com.google.android.exoplayer2.metadata.MetadataInputBuffer)3 Nullable (androidx.annotation.Nullable)2 Id3Decoder (com.google.android.exoplayer2.metadata.id3.Id3Decoder)2 Uri (android.net.Uri)1 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)1 DataSource (com.google.android.exoplayer2.upstream.DataSource)1 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)1 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1 EOFException (java.io.EOFException)1