diff --git a/library/common/src/main/java/com/google/android/exoplayer2/metadata/flac/VorbisComment.java b/library/common/src/main/java/com/google/android/exoplayer2/metadata/flac/VorbisComment.java index 9f44cdf393..3ab60541a9 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/metadata/flac/VorbisComment.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/metadata/flac/VorbisComment.java @@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Util.castNonNull; import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.MediaMetadata; import com.google.android.exoplayer2.metadata.Metadata; /** A vorbis comment. */ @@ -45,6 +46,29 @@ public final class VorbisComment implements Metadata.Entry { this.value = castNonNull(in.readString()); } + @Override + public void populateMediaMetadata(MediaMetadata.Builder builder) { + switch (key) { + case "TITLE": + builder.setTitle(value); + break; + case "ARTIST": + builder.setArtist(value); + break; + case "ALBUM": + builder.setAlbumTitle(value); + break; + case "ALBUMARTIST": + builder.setAlbumArtist(value); + break; + case "DESCRIPTION": + builder.setDescription(value); + break; + default: + break; + } + } + @Override public String toString() { return "VC: " + key + "=" + value; diff --git a/library/common/src/test/java/com/google/android/exoplayer2/metadata/flac/VorbisCommentTest.java b/library/common/src/test/java/com/google/android/exoplayer2/metadata/flac/VorbisCommentTest.java index e3a12a8013..4c0f0592de 100644 --- a/library/common/src/test/java/com/google/android/exoplayer2/metadata/flac/VorbisCommentTest.java +++ b/library/common/src/test/java/com/google/android/exoplayer2/metadata/flac/VorbisCommentTest.java @@ -19,6 +19,10 @@ import static com.google.common.truth.Truth.assertThat; import android.os.Parcel; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.android.exoplayer2.MediaMetadata; +import com.google.android.exoplayer2.metadata.Metadata; +import com.google.common.collect.ImmutableList; +import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,4 +43,32 @@ public final class VorbisCommentTest { parcel.recycle(); } + + @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 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); + } }