Populate MediaMetadata from VorbisComment.

PiperOrigin-RevId: 378844617
This commit is contained in:
samrobinson 2021-06-11 11:59:37 +01:00 committed by Oliver Woodman
parent 53d67daaef
commit 22f05e549a
2 changed files with 56 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Util.castNonNull;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
/** A vorbis comment. */ /** A vorbis comment. */
@ -45,6 +46,29 @@ public final class VorbisComment implements Metadata.Entry {
this.value = castNonNull(in.readString()); 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 @Override
public String toString() { public String toString() {
return "VC: " + key + "=" + value; return "VC: " + key + "=" + value;

View File

@ -19,6 +19,10 @@ import static com.google.common.truth.Truth.assertThat;
import android.os.Parcel; import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -39,4 +43,32 @@ public final class VorbisCommentTest {
parcel.recycle(); 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<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);
}
} }