mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add playlist MediaMetadata to the Player.
PiperOrigin-RevId: 378407609
This commit is contained in:
parent
35202cc1a2
commit
5204bb0d44
9 changed files with 120 additions and 1 deletions
|
|
@ -528,6 +528,18 @@ public final class CastPlayer extends BasePlayer {
|
||||||
return MediaMetadata.EMPTY;
|
return MediaMetadata.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaMetadata getPlaylistMediaMetadata() {
|
||||||
|
// CastPlayer does not currently support metadata.
|
||||||
|
return MediaMetadata.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This method is not supported and does nothing. */
|
||||||
|
@Override
|
||||||
|
public void setPlaylistMediaMetadata(MediaMetadata mediaMetadata) {
|
||||||
|
// CastPlayer does not currently support metadata.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Timeline getCurrentTimeline() {
|
public Timeline getCurrentTimeline() {
|
||||||
return currentTimeline;
|
return currentTimeline;
|
||||||
|
|
|
||||||
|
|
@ -348,6 +348,16 @@ public class ForwardingPlayer implements Player {
|
||||||
return player.getMediaMetadata();
|
return player.getMediaMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaMetadata getPlaylistMediaMetadata() {
|
||||||
|
return player.getPlaylistMediaMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlaylistMediaMetadata(MediaMetadata mediaMetadata) {
|
||||||
|
player.setPlaylistMediaMetadata(mediaMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Object getCurrentManifest() {
|
public Object getCurrentManifest() {
|
||||||
|
|
@ -613,6 +623,11 @@ public class ForwardingPlayer implements Player {
|
||||||
eventListener.onMediaMetadataChanged(mediaMetadata);
|
eventListener.onMediaMetadataChanged(mediaMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaylistMediaMetadataChanged(MediaMetadata mediaMetadata) {
|
||||||
|
eventListener.onPlaylistMediaMetadataChanged(mediaMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIsLoadingChanged(boolean isLoading) {
|
public void onIsLoadingChanged(boolean isLoading) {
|
||||||
eventListener.onIsLoadingChanged(isLoading);
|
eventListener.onIsLoadingChanged(isLoading);
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,9 @@ public interface Player {
|
||||||
*/
|
*/
|
||||||
default void onMediaMetadataChanged(MediaMetadata mediaMetadata) {}
|
default void onMediaMetadataChanged(MediaMetadata mediaMetadata) {}
|
||||||
|
|
||||||
|
/** Called when the playlist {@link MediaMetadata} changes. */
|
||||||
|
default void onPlaylistMediaMetadataChanged(MediaMetadata mediaMetadata) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the player starts or stops loading the source.
|
* Called when the player starts or stops loading the source.
|
||||||
*
|
*
|
||||||
|
|
@ -1047,7 +1050,8 @@ public interface Player {
|
||||||
EVENT_POSITION_DISCONTINUITY,
|
EVENT_POSITION_DISCONTINUITY,
|
||||||
EVENT_PLAYBACK_PARAMETERS_CHANGED,
|
EVENT_PLAYBACK_PARAMETERS_CHANGED,
|
||||||
EVENT_AVAILABLE_COMMANDS_CHANGED,
|
EVENT_AVAILABLE_COMMANDS_CHANGED,
|
||||||
EVENT_MEDIA_METADATA_CHANGED
|
EVENT_MEDIA_METADATA_CHANGED,
|
||||||
|
EVENT_PLAYLIST_MEDIA_METADATA_CHANGED
|
||||||
})
|
})
|
||||||
@interface EventFlags {}
|
@interface EventFlags {}
|
||||||
/** {@link #getCurrentTimeline()} changed. */
|
/** {@link #getCurrentTimeline()} changed. */
|
||||||
|
|
@ -1085,6 +1089,8 @@ public interface Player {
|
||||||
int EVENT_AVAILABLE_COMMANDS_CHANGED = 14;
|
int EVENT_AVAILABLE_COMMANDS_CHANGED = 14;
|
||||||
/** {@link #getMediaMetadata()} changed. */
|
/** {@link #getMediaMetadata()} changed. */
|
||||||
int EVENT_MEDIA_METADATA_CHANGED = 15;
|
int EVENT_MEDIA_METADATA_CHANGED = 15;
|
||||||
|
/** {@link #getPlaylistMediaMetadata()} changed. */
|
||||||
|
int EVENT_PLAYLIST_MEDIA_METADATA_CHANGED = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands that can be executed on a {@code Player}. One of {@link #COMMAND_PLAY_PAUSE}, {@link
|
* Commands that can be executed on a {@code Player}. One of {@link #COMMAND_PLAY_PAUSE}, {@link
|
||||||
|
|
@ -1723,6 +1729,15 @@ public interface Player {
|
||||||
*/
|
*/
|
||||||
MediaMetadata getMediaMetadata();
|
MediaMetadata getMediaMetadata();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the playlist {@link MediaMetadata}, as set by {@link
|
||||||
|
* #setPlaylistMediaMetadata(MediaMetadata)}, or {@link MediaMetadata#EMPTY} if not supported.
|
||||||
|
*/
|
||||||
|
MediaMetadata getPlaylistMediaMetadata();
|
||||||
|
|
||||||
|
/** Sets the playlist {@link MediaMetadata}. */
|
||||||
|
void setPlaylistMediaMetadata(MediaMetadata mediaMetadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current manifest. The type depends on the type of media being played. May be null.
|
* Returns the current manifest. The type depends on the type of media being played. May be null.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
private boolean pauseAtEndOfMediaItems;
|
private boolean pauseAtEndOfMediaItems;
|
||||||
private Commands availableCommands;
|
private Commands availableCommands;
|
||||||
private MediaMetadata mediaMetadata;
|
private MediaMetadata mediaMetadata;
|
||||||
|
private MediaMetadata playlistMediaMetadata;
|
||||||
private long fastForwardIncrementMs;
|
private long fastForwardIncrementMs;
|
||||||
private long rewindIncrementMs;
|
private long rewindIncrementMs;
|
||||||
|
|
||||||
|
|
@ -213,6 +214,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
.add(COMMAND_SEEK_TO_MEDIA_ITEM)
|
.add(COMMAND_SEEK_TO_MEDIA_ITEM)
|
||||||
.build();
|
.build();
|
||||||
mediaMetadata = MediaMetadata.EMPTY;
|
mediaMetadata = MediaMetadata.EMPTY;
|
||||||
|
playlistMediaMetadata = MediaMetadata.EMPTY;
|
||||||
fastForwardIncrementMs = DEFAULT_FAST_FORWARD_INCREMENT_MS;
|
fastForwardIncrementMs = DEFAULT_FAST_FORWARD_INCREMENT_MS;
|
||||||
rewindIncrementMs = DEFAULT_REWIND_INCREMENT_MS;
|
rewindIncrementMs = DEFAULT_REWIND_INCREMENT_MS;
|
||||||
maskingWindowIndex = C.INDEX_UNSET;
|
maskingWindowIndex = C.INDEX_UNSET;
|
||||||
|
|
@ -1026,6 +1028,23 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
EVENT_MEDIA_METADATA_CHANGED, listener -> listener.onMediaMetadataChanged(mediaMetadata));
|
EVENT_MEDIA_METADATA_CHANGED, listener -> listener.onMediaMetadataChanged(mediaMetadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaMetadata getPlaylistMediaMetadata() {
|
||||||
|
return playlistMediaMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlaylistMediaMetadata(MediaMetadata playlistMediaMetadata) {
|
||||||
|
checkNotNull(playlistMediaMetadata);
|
||||||
|
if (playlistMediaMetadata.equals(this.playlistMediaMetadata)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.playlistMediaMetadata = playlistMediaMetadata;
|
||||||
|
listeners.sendEvent(
|
||||||
|
EVENT_PLAYLIST_MEDIA_METADATA_CHANGED,
|
||||||
|
listener -> listener.onPlaylistMediaMetadataChanged(this.playlistMediaMetadata));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Timeline getCurrentTimeline() {
|
public Timeline getCurrentTimeline() {
|
||||||
return playbackInfo.timeline;
|
return playbackInfo.timeline;
|
||||||
|
|
|
||||||
|
|
@ -1689,6 +1689,16 @@ public class SimpleExoPlayer extends BasePlayer
|
||||||
return player.getMediaMetadata();
|
return player.getMediaMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaMetadata getPlaylistMediaMetadata() {
|
||||||
|
return player.getPlaylistMediaMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlaylistMediaMetadata(MediaMetadata mediaMetadata) {
|
||||||
|
player.setPlaylistMediaMetadata(mediaMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Timeline getCurrentTimeline() {
|
public Timeline getCurrentTimeline() {
|
||||||
verifyApplicationThread();
|
verifyApplicationThread();
|
||||||
|
|
|
||||||
|
|
@ -749,6 +749,15 @@ public class AnalyticsCollector
|
||||||
listener -> listener.onMediaMetadataChanged(eventTime, mediaMetadata));
|
listener -> listener.onMediaMetadataChanged(eventTime, mediaMetadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaylistMediaMetadataChanged(MediaMetadata playlistMediaMetadata) {
|
||||||
|
EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
|
||||||
|
sendEvent(
|
||||||
|
eventTime,
|
||||||
|
AnalyticsListener.EVENT_PLAYLIST_MEDIA_METADATA_CHANGED,
|
||||||
|
listener -> listener.onPlaylistMediaMetadataChanged(eventTime, playlistMediaMetadata));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // Implementing and calling deprecated listener method.
|
@SuppressWarnings("deprecation") // Implementing and calling deprecated listener method.
|
||||||
@Override
|
@Override
|
||||||
public final void onSeekProcessed() {
|
public final void onSeekProcessed() {
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ public interface AnalyticsListener {
|
||||||
EVENT_POSITION_DISCONTINUITY,
|
EVENT_POSITION_DISCONTINUITY,
|
||||||
EVENT_PLAYBACK_PARAMETERS_CHANGED,
|
EVENT_PLAYBACK_PARAMETERS_CHANGED,
|
||||||
EVENT_MEDIA_METADATA_CHANGED,
|
EVENT_MEDIA_METADATA_CHANGED,
|
||||||
|
EVENT_PLAYLIST_MEDIA_METADATA_CHANGED,
|
||||||
EVENT_LOAD_STARTED,
|
EVENT_LOAD_STARTED,
|
||||||
EVENT_LOAD_COMPLETED,
|
EVENT_LOAD_COMPLETED,
|
||||||
EVENT_LOAD_CANCELED,
|
EVENT_LOAD_CANCELED,
|
||||||
|
|
@ -248,6 +249,8 @@ public interface AnalyticsListener {
|
||||||
int EVENT_PLAYBACK_PARAMETERS_CHANGED = Player.EVENT_PLAYBACK_PARAMETERS_CHANGED;
|
int EVENT_PLAYBACK_PARAMETERS_CHANGED = Player.EVENT_PLAYBACK_PARAMETERS_CHANGED;
|
||||||
/** {@link Player#getMediaMetadata()} changed. */
|
/** {@link Player#getMediaMetadata()} changed. */
|
||||||
int EVENT_MEDIA_METADATA_CHANGED = Player.EVENT_MEDIA_METADATA_CHANGED;
|
int EVENT_MEDIA_METADATA_CHANGED = Player.EVENT_MEDIA_METADATA_CHANGED;
|
||||||
|
/** {@link Player#getPlaylistMediaMetadata()} changed. */
|
||||||
|
int EVENT_PLAYLIST_MEDIA_METADATA_CHANGED = Player.EVENT_PLAYLIST_MEDIA_METADATA_CHANGED;
|
||||||
/** A source started loading data. */
|
/** A source started loading data. */
|
||||||
int EVENT_LOAD_STARTED = 1000; // Intentional gap to leave space for new Player events
|
int EVENT_LOAD_STARTED = 1000; // Intentional gap to leave space for new Player events
|
||||||
/** A source started completed loading data. */
|
/** A source started completed loading data. */
|
||||||
|
|
@ -658,6 +661,15 @@ public interface AnalyticsListener {
|
||||||
*/
|
*/
|
||||||
default void onMediaMetadataChanged(EventTime eventTime, MediaMetadata mediaMetadata) {}
|
default void onMediaMetadataChanged(EventTime eventTime, MediaMetadata mediaMetadata) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the playlist {@link MediaMetadata} changes.
|
||||||
|
*
|
||||||
|
* @param eventTime The event time.
|
||||||
|
* @param playlistMediaMetadata The playlist {@link MediaMetadata}.
|
||||||
|
*/
|
||||||
|
default void onPlaylistMediaMetadataChanged(
|
||||||
|
EventTime eventTime, MediaMetadata playlistMediaMetadata) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a media source started loading data.
|
* Called when a media source started loading data.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.atLeast;
|
import static org.mockito.Mockito.atLeast;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
@ -61,6 +62,22 @@ public class SimpleExoPlayerTest {
|
||||||
assertThat(builderThrow.get()).isNull();
|
assertThat(builderThrow.get()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPlaybackMediaMetadataChanged_calledWhenPlaybackMediaMetadataSet() {
|
||||||
|
SimpleExoPlayer player =
|
||||||
|
new SimpleExoPlayer.Builder(ApplicationProvider.getApplicationContext()).build();
|
||||||
|
Player.Listener playerListener = mock(Player.Listener.class);
|
||||||
|
player.addListener(playerListener);
|
||||||
|
AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
|
||||||
|
player.addAnalyticsListener(analyticsListener);
|
||||||
|
|
||||||
|
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("test").build();
|
||||||
|
player.setPlaylistMediaMetadata(mediaMetadata);
|
||||||
|
|
||||||
|
verify(playerListener).onPlaylistMediaMetadataChanged(mediaMetadata);
|
||||||
|
verify(analyticsListener).onPlaylistMediaMetadataChanged(any(), eq(mediaMetadata));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void release_triggersAllPendingEventsInAnalyticsListeners() throws Exception {
|
public void release_triggersAllPendingEventsInAnalyticsListeners() throws Exception {
|
||||||
SimpleExoPlayer player =
|
SimpleExoPlayer player =
|
||||||
|
|
|
||||||
|
|
@ -390,6 +390,16 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaMetadata getPlaylistMediaMetadata() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlaylistMediaMetadata(MediaMetadata mediaMetadata) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Timeline getCurrentTimeline() {
|
public Timeline getCurrentTimeline() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue