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");
}
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");
}
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);
}
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);
}
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");
}
Aggregations