Populate MediaMetadata from VorbisComment.
PiperOrigin-RevId: 378844617
This commit is contained in:
parent
53d67daaef
commit
22f05e549a
@ -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;
|
||||
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user