mirror of
https://github.com/samsonjs/media.git
synced 2026-03-31 10:25:48 +00:00
Populate ICY headers into MediaMetadata
Populate ICY headers into MediaMetadata so that they can propagate to the app via AnalyticsListener#onMediaMetadataChanged(). This change copies IcyHeaders.name into MediaMetadata.description and IcyHeaders.genre into MediaMetadata.genre. Note: MediaItem.metadata maintain their precedence and overwrite any ICY headers parsed. Issue: google/ExoPlayer#9677 #minor-release PiperOrigin-RevId: 410495676
This commit is contained in:
parent
2110769323
commit
349160a5cf
5 changed files with 61 additions and 2 deletions
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
### dev-v2 (not yet released)
|
||||
|
||||
* Metadata:
|
||||
* Propagate ICY header fields `name` and `genre` to
|
||||
`MediaMetadata.station` and `MediaMetadata.genre` respectively so that
|
||||
they reach the app via `Player.Listener.onMediaMetadataChanged()`
|
||||
((#9677)[https://github.com/google/ExoPlayer/issues/9677]).
|
||||
|
||||
* HLS:
|
||||
* Correctly populate `Format.label` for audio only HLS streams
|
||||
([#9608](https://github.com/google/ExoPlayer/issues/9608)).
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
@Nullable private Integer totalDiscCount;
|
||||
@Nullable private CharSequence genre;
|
||||
@Nullable private CharSequence compilation;
|
||||
@Nullable private CharSequence station;
|
||||
@Nullable private Bundle extras;
|
||||
|
||||
public Builder() {}
|
||||
|
|
@ -110,6 +111,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
this.totalDiscCount = mediaMetadata.totalDiscCount;
|
||||
this.genre = mediaMetadata.genre;
|
||||
this.compilation = mediaMetadata.compilation;
|
||||
this.station = mediaMetadata.station;
|
||||
this.extras = mediaMetadata.extras;
|
||||
}
|
||||
|
||||
|
|
@ -346,6 +348,12 @@ public final class MediaMetadata implements Bundleable {
|
|||
return this;
|
||||
}
|
||||
|
||||
/** Sets the name of the station streaming the media. */
|
||||
public Builder setStation(@Nullable CharSequence station) {
|
||||
this.station = station;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets the extras {@link Bundle}. */
|
||||
public Builder setExtras(@Nullable Bundle extras) {
|
||||
this.extras = extras;
|
||||
|
|
@ -485,6 +493,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
if (mediaMetadata.compilation != null) {
|
||||
setCompilation(mediaMetadata.compilation);
|
||||
}
|
||||
if (mediaMetadata.station != null) {
|
||||
setStation(mediaMetadata.station);
|
||||
}
|
||||
if (mediaMetadata.extras != null) {
|
||||
setExtras(mediaMetadata.extras);
|
||||
}
|
||||
|
|
@ -679,6 +690,8 @@ public final class MediaMetadata implements Bundleable {
|
|||
@Nullable public final CharSequence genre;
|
||||
/** Optional compilation. */
|
||||
@Nullable public final CharSequence compilation;
|
||||
/** Optional name of the station streaming the media. */
|
||||
@Nullable public final CharSequence station;
|
||||
|
||||
/**
|
||||
* Optional extras {@link Bundle}.
|
||||
|
|
@ -720,6 +733,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
this.totalDiscCount = builder.totalDiscCount;
|
||||
this.genre = builder.genre;
|
||||
this.compilation = builder.compilation;
|
||||
this.station = builder.station;
|
||||
this.extras = builder.extras;
|
||||
}
|
||||
|
||||
|
|
@ -766,7 +780,8 @@ public final class MediaMetadata implements Bundleable {
|
|||
&& Util.areEqual(discNumber, that.discNumber)
|
||||
&& Util.areEqual(totalDiscCount, that.totalDiscCount)
|
||||
&& Util.areEqual(genre, that.genre)
|
||||
&& Util.areEqual(compilation, that.compilation);
|
||||
&& Util.areEqual(compilation, that.compilation)
|
||||
&& Util.areEqual(station, that.station);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -801,7 +816,8 @@ public final class MediaMetadata implements Bundleable {
|
|||
discNumber,
|
||||
totalDiscCount,
|
||||
genre,
|
||||
compilation);
|
||||
compilation,
|
||||
station);
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
|
|
@ -839,6 +855,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
FIELD_TOTAL_DISC_COUNT,
|
||||
FIELD_GENRE,
|
||||
FIELD_COMPILATION,
|
||||
FIELD_STATION,
|
||||
FIELD_EXTRAS
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
|
@ -873,6 +890,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
private static final int FIELD_GENRE = 27;
|
||||
private static final int FIELD_COMPILATION = 28;
|
||||
private static final int FIELD_ARTWORK_DATA_TYPE = 29;
|
||||
private static final int FIELD_STATION = 30;
|
||||
private static final int FIELD_EXTRAS = 1000;
|
||||
|
||||
@Override
|
||||
|
|
@ -893,6 +911,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
bundle.putCharSequence(keyForField(FIELD_CONDUCTOR), conductor);
|
||||
bundle.putCharSequence(keyForField(FIELD_GENRE), genre);
|
||||
bundle.putCharSequence(keyForField(FIELD_COMPILATION), compilation);
|
||||
bundle.putCharSequence(keyForField(FIELD_STATION), station);
|
||||
|
||||
if (userRating != null) {
|
||||
bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle());
|
||||
|
|
@ -970,6 +989,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
.setConductor(bundle.getCharSequence(keyForField(FIELD_CONDUCTOR)))
|
||||
.setGenre(bundle.getCharSequence(keyForField(FIELD_GENRE)))
|
||||
.setCompilation(bundle.getCharSequence(keyForField(FIELD_COMPILATION)))
|
||||
.setStation(bundle.getCharSequence(keyForField(FIELD_STATION)))
|
||||
.setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS)));
|
||||
|
||||
if (bundle.containsKey(keyForField(FIELD_USER_RATING))) {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public class MediaMetadataTest {
|
|||
assertThat(mediaMetadata.totalDiscCount).isNull();
|
||||
assertThat(mediaMetadata.genre).isNull();
|
||||
assertThat(mediaMetadata.compilation).isNull();
|
||||
assertThat(mediaMetadata.station).isNull();
|
||||
assertThat(mediaMetadata.extras).isNull();
|
||||
}
|
||||
|
||||
|
|
@ -149,6 +150,7 @@ public class MediaMetadataTest {
|
|||
.setTotalDiscCount(3)
|
||||
.setGenre("Pop")
|
||||
.setCompilation("Amazing songs.")
|
||||
.setStation("radio station")
|
||||
.setExtras(extras)
|
||||
.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import android.os.Parcelable;
|
|||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.MediaMetadata;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
|
|
@ -169,6 +170,16 @@ public final class IcyHeaders implements Metadata.Entry {
|
|||
metadataInterval = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateMediaMetadata(MediaMetadata.Builder builder) {
|
||||
if (name != null) {
|
||||
builder.setStation(name);
|
||||
}
|
||||
if (genre != null) {
|
||||
builder.setGenre(genre);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ 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 org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
|
@ -45,4 +46,23 @@ public final class IcyHeadersTest {
|
|||
// Assert equals.
|
||||
assertThat(fromParcelIcyHeaders).isEqualTo(icyHeaders);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populateMediaMetadata() {
|
||||
IcyHeaders headers =
|
||||
new IcyHeaders(
|
||||
/* bitrate= */ 1234,
|
||||
/* genre= */ "pop",
|
||||
/* name= */ "radio station",
|
||||
/* url= */ "url",
|
||||
/* isPublic= */ true,
|
||||
/* metadataInterval= */ 5678);
|
||||
MediaMetadata.Builder builder = new MediaMetadata.Builder();
|
||||
|
||||
headers.populateMediaMetadata(builder);
|
||||
MediaMetadata mediaMetadata = builder.build();
|
||||
|
||||
assertThat(mediaMetadata.station.toString()).isEqualTo("radio station");
|
||||
assertThat(mediaMetadata.genre.toString()).isEqualTo("pop");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue