Search in sources :

Example 1 with VorbisComment

use of androidx.media3.extractor.metadata.vorbis.VorbisComment in project media by androidx.

the class FlacMetadataReaderTest method readMetadataBlock_vorbisCommentBlock_updatesStreamMetadata.

@Test
public void readMetadataBlock_vorbisCommentBlock_updatesStreamMetadata() throws Exception {
    ExtractorInput input = buildExtractorInput("media/flac/bear_with_vorbis_comments.flac");
    // Skip to Vorbis comment block.
    input.skipFully(640);
    FlacStreamMetadataHolder metadataHolder = new FlacStreamMetadataHolder(buildStreamMetadata());
    long originalSampleRate = metadataHolder.flacStreamMetadata.sampleRate;
    FlacMetadataReader.readMetadataBlock(input, metadataHolder);
    assertThat(metadataHolder.flacStreamMetadata).isNotNull();
    // Check that metadata passed has not been erased.
    assertThat(metadataHolder.flacStreamMetadata.sampleRate).isEqualTo(originalSampleRate);
    Metadata metadata = metadataHolder.flacStreamMetadata.getMetadataCopyWithAppendedEntriesFrom(null);
    assertThat(metadata).isNotNull();
    VorbisComment vorbisComment = (VorbisComment) metadata.get(0);
    assertThat(vorbisComment.key).isEqualTo("TITLE");
    assertThat(vorbisComment.value).isEqualTo("test title");
}
Also used : FlacStreamMetadataHolder(androidx.media3.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) Metadata(androidx.media3.common.Metadata) VorbisComment(androidx.media3.extractor.metadata.vorbis.VorbisComment) Test(org.junit.Test)

Example 2 with VorbisComment

use of androidx.media3.extractor.metadata.vorbis.VorbisComment in project media by androidx.

the class FlacStreamMetadataTest method parseInvalidVorbisComment.

@Test
public void parseInvalidVorbisComment() {
    ArrayList<String> commentsList = new ArrayList<>();
    commentsList.add("TitleSong");
    commentsList.add("Artist=Singer");
    Metadata metadata = new FlacStreamMetadata(/* minBlockSizeSamples= */
    0, /* maxBlockSizeSamples= */
    0, /* minFrameSize= */
    0, /* maxFrameSize= */
    0, /* sampleRate= */
    0, /* channels= */
    0, /* bitsPerSample= */
    0, /* totalSamples= */
    0, commentsList, /* pictureFrames= */
    new ArrayList<>()).getMetadataCopyWithAppendedEntriesFrom(/* other= */
    null);
    assertThat(metadata.length()).isEqualTo(1);
    VorbisComment commentFrame = (VorbisComment) metadata.get(0);
    assertThat(commentFrame.key).isEqualTo("Artist");
    assertThat(commentFrame.value).isEqualTo("Singer");
}
Also used : ArrayList(java.util.ArrayList) Metadata(androidx.media3.common.Metadata) VorbisComment(androidx.media3.extractor.metadata.vorbis.VorbisComment) Test(org.junit.Test)

Example 3 with VorbisComment

use of androidx.media3.extractor.metadata.vorbis.VorbisComment in project media by androidx.

the class VorbisCommentTest method populateMediaMetadata_setsMediaMetadataValues.

@Test
public void populateMediaMetadata_setsMediaMetadataValues() {
    String title = "the title";
    String artist = "artist";
    String albumTitle = "album title";
    String albumArtist = "album Artist";
    String description = "a description about the audio.";
    List<Metadata.Entry> entries = ImmutableList.of(new VorbisComment("TITLE", title), new VorbisComment("ARTIST", artist), new VorbisComment("ALBUM", albumTitle), new VorbisComment("ALBUMARTIST", albumArtist), new VorbisComment("DESCRIPTION", description));
    MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
    for (Metadata.Entry entry : entries) {
        entry.populateMediaMetadata(builder);
    }
    MediaMetadata mediaMetadata = builder.build();
    assertThat(mediaMetadata.title.toString()).isEqualTo(title);
    assertThat(mediaMetadata.artist.toString()).isEqualTo(artist);
    assertThat(mediaMetadata.albumTitle.toString()).isEqualTo(albumTitle);
    assertThat(mediaMetadata.albumArtist.toString()).isEqualTo(albumArtist);
    assertThat(mediaMetadata.description.toString()).isEqualTo(description);
}
Also used : MediaMetadata(androidx.media3.common.MediaMetadata) Metadata(androidx.media3.common.Metadata) MediaMetadata(androidx.media3.common.MediaMetadata) Test(org.junit.Test)

Example 4 with VorbisComment

use of androidx.media3.extractor.metadata.vorbis.VorbisComment in project media by androidx.

the class VorbisUtil method parseVorbisComments.

/**
 * Builds a {@link Metadata} instance from a list of Vorbis Comments.
 *
 * <p>METADATA_BLOCK_PICTURE comments will be transformed into {@link PictureFrame} entries. All
 * others will be transformed into {@link VorbisComment} entries.
 *
 * @param vorbisComments The raw input of comments, as a key-value pair KEY=VAL.
 * @return The fully parsed Metadata instance. Null if no vorbis comments could be parsed.
 */
@Nullable
public static Metadata parseVorbisComments(List<String> vorbisComments) {
    List<Entry> metadataEntries = new ArrayList<>();
    for (int i = 0; i < vorbisComments.size(); i++) {
        String vorbisComment = vorbisComments.get(i);
        String[] keyAndValue = Util.splitAtFirst(vorbisComment, "=");
        if (keyAndValue.length != 2) {
            Log.w(TAG, "Failed to parse Vorbis comment: " + vorbisComment);
            continue;
        }
        if (keyAndValue[0].equals("METADATA_BLOCK_PICTURE")) {
            // Decode it from Base64 and transform it into a PictureFrame.
            try {
                byte[] decoded = Base64.decode(keyAndValue[1], Base64.DEFAULT);
                metadataEntries.add(PictureFrame.fromPictureBlock(new ParsableByteArray(decoded)));
            } catch (RuntimeException e) {
                Log.w(TAG, "Failed to parse vorbis picture", e);
            }
        } else {
            VorbisComment entry = new VorbisComment(keyAndValue[0], keyAndValue[1]);
            metadataEntries.add(entry);
        }
    }
    return metadataEntries.isEmpty() ? null : new Metadata(metadataEntries);
}
Also used : ParsableByteArray(androidx.media3.common.util.ParsableByteArray) Entry(androidx.media3.common.Metadata.Entry) ArrayList(java.util.ArrayList) Metadata(androidx.media3.common.Metadata) VorbisComment(androidx.media3.extractor.metadata.vorbis.VorbisComment) Nullable(androidx.annotation.Nullable)

Example 5 with VorbisComment

use of androidx.media3.extractor.metadata.vorbis.VorbisComment in project media by androidx.

the class FlacStreamMetadataTest method parseVorbisComments.

@Test
public void parseVorbisComments() {
    ArrayList<String> commentsList = new ArrayList<>();
    commentsList.add("Title=Song");
    commentsList.add("Artist=Singer");
    Metadata metadata = new FlacStreamMetadata(/* minBlockSizeSamples= */
    0, /* maxBlockSizeSamples= */
    0, /* minFrameSize= */
    0, /* maxFrameSize= */
    0, /* sampleRate= */
    0, /* channels= */
    0, /* bitsPerSample= */
    0, /* totalSamples= */
    0, commentsList, /* pictureFrames= */
    new ArrayList<>()).getMetadataCopyWithAppendedEntriesFrom(/* other= */
    null);
    assertThat(metadata.length()).isEqualTo(2);
    VorbisComment commentFrame = (VorbisComment) metadata.get(0);
    assertThat(commentFrame.key).isEqualTo("Title");
    assertThat(commentFrame.value).isEqualTo("Song");
    commentFrame = (VorbisComment) metadata.get(1);
    assertThat(commentFrame.key).isEqualTo("Artist");
    assertThat(commentFrame.value).isEqualTo("Singer");
}
Also used : ArrayList(java.util.ArrayList) Metadata(androidx.media3.common.Metadata) VorbisComment(androidx.media3.extractor.metadata.vorbis.VorbisComment) Test(org.junit.Test)

Aggregations

Metadata (androidx.media3.common.Metadata)6 VorbisComment (androidx.media3.extractor.metadata.vorbis.VorbisComment)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Nullable (androidx.annotation.Nullable)1 MediaMetadata (androidx.media3.common.MediaMetadata)1 Entry (androidx.media3.common.Metadata.Entry)1 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)1 FlacStreamMetadataHolder (androidx.media3.extractor.FlacMetadataReader.FlacStreamMetadataHolder)1 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)1