Add getMediaMetadata to Player and SimpleExoPlayer.

PiperOrigin-RevId: 366240390
This commit is contained in:
samrobinson 2021-04-01 14:34:53 +01:00 committed by Oliver Woodman
parent a317746eff
commit 3d3c90b89d
6 changed files with 44 additions and 0 deletions

View file

@ -49,6 +49,7 @@
* Core:
* Move `getRendererCount` and `getRendererType` methods from `Player` to
`ExoPlayer`.
* Add `getMediaMetadata` to `Player` interface.
* Reset playback speed when live playback speed control becomes unused
([#8664](https://github.com/google/ExoPlayer/issues/8664)).
* Fix playback position issue when re-preparing playback after a

View file

@ -25,6 +25,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
@ -566,6 +567,12 @@ public final class CastPlayer extends BasePlayer {
return Collections.emptyList();
}
@Override
public MediaMetadata getMediaMetadata() {
// CastPlayer does not currently support metadata.
return MediaMetadata.EMPTY;
}
@Override
public Timeline getCurrentTimeline() {
return currentTimeline;

View file

@ -35,6 +35,7 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.util.ExoFlags;
import com.google.android.exoplayer2.util.StableApiCandidate;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.VideoListener;
@ -1749,6 +1750,16 @@ public interface Player {
*/
List<Metadata> getCurrentStaticMetadata();
/**
* Returns the current combined {@link MediaMetadata}, or {@link MediaMetadata#EMPTY} if not
* supported.
*
* <p>This {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} and the
* static and dynamic metadata sourced from {@link EventListener#onStaticMetadataChanged(List)}
* and {@link MetadataOutput#onMetadata(Metadata)}.
*/
MediaMetadata getMediaMetadata();
/**
* Returns the current manifest. The type depends on the type of media being played. May be null.
*/

View file

@ -974,6 +974,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
return playbackInfo.staticMetadata;
}
@Override
public MediaMetadata getMediaMetadata() {
// Unsupported operation.
return MediaMetadata.EMPTY;
}
@Override
public Timeline getCurrentTimeline() {
return playbackInfo.timeline;

View file

@ -609,6 +609,7 @@ public class SimpleExoPlayer extends BasePlayer
private boolean isPriorityTaskManagerRegistered;
private boolean playerReleased;
private DeviceInfo deviceInfo;
private MediaMetadata currentMediaMetadata;
/** @deprecated Use the {@link Builder} and pass it to {@link #SimpleExoPlayer(Builder)}. */
@Deprecated
@ -716,6 +717,7 @@ public class SimpleExoPlayer extends BasePlayer
wifiLockManager = new WifiLockManager(builder.context);
wifiLockManager.setEnabled(builder.wakeMode == C.WAKE_MODE_NETWORK);
deviceInfo = createDeviceInfo(streamVolumeManager);
currentMediaMetadata = MediaMetadata.EMPTY;
sendRendererMessage(C.TRACK_TYPE_AUDIO, Renderer.MSG_SET_AUDIO_SESSION_ID, audioSessionId);
sendRendererMessage(C.TRACK_TYPE_VIDEO, Renderer.MSG_SET_AUDIO_SESSION_ID, audioSessionId);
@ -1620,6 +1622,11 @@ public class SimpleExoPlayer extends BasePlayer
return player.getCurrentStaticMetadata();
}
@Override
public MediaMetadata getMediaMetadata() {
return currentMediaMetadata;
}
@Override
public Timeline getCurrentTimeline() {
verifyApplicationThread();
@ -2275,6 +2282,12 @@ public class SimpleExoPlayer extends BasePlayer
}
}
@Override
public void onMediaItemTransition(
@Nullable MediaItem mediaItem, @MediaItemTransitionReason int reason) {
currentMediaMetadata = mediaItem == null ? MediaMetadata.EMPTY : mediaItem.mediaMetadata;
}
@Override
public void onPlaybackStateChanged(@State int playbackState) {
updateWakeAndWifiLock();

View file

@ -21,6 +21,7 @@ import com.google.android.exoplayer2.BasePlayer;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.PlayerMessage;
@ -356,6 +357,11 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
throw new UnsupportedOperationException();
}
@Override
public MediaMetadata getMediaMetadata() {
throw new UnsupportedOperationException();
}
@Override
public Timeline getCurrentTimeline() {
throw new UnsupportedOperationException();