mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
make MediaSessionConnector depend only to the Player interface
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=162604746
This commit is contained in:
parent
33f5bd6aed
commit
8d56f904a0
3 changed files with 50 additions and 55 deletions
|
|
@ -32,11 +32,9 @@ import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
|
||||||
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||||
|
|
@ -46,8 +44,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mediates between a {@link MediaSessionCompat} and an {@link SimpleExoPlayer} instance set with
|
* Mediates between a {@link MediaSessionCompat} and an {@link Player} instance set with
|
||||||
* {@link #setPlayer(SimpleExoPlayer, CustomActionProvider...)}.
|
* {@link #setPlayer(Player, PlaybackPreparer, CustomActionProvider...)}.
|
||||||
* <p>
|
* <p>
|
||||||
* By default the {@code MediaSessionConnector} listens for {@link #DEFAULT_PLAYBACK_ACTIONS} sent
|
* By default the {@code MediaSessionConnector} listens for {@link #DEFAULT_PLAYBACK_ACTIONS} sent
|
||||||
* by a media controller and realizes these actions by calling appropriate ExoPlayer methods.
|
* by a media controller and realizes these actions by calling appropriate ExoPlayer methods.
|
||||||
|
|
@ -110,28 +108,32 @@ public final class MediaSessionConnector {
|
||||||
* Normally preparing playback includes preparing the player with a
|
* Normally preparing playback includes preparing the player with a
|
||||||
* {@link com.google.android.exoplayer2.source.MediaSource} and setting up the media session queue
|
* {@link com.google.android.exoplayer2.source.MediaSource} and setting up the media session queue
|
||||||
* with a corresponding list of queue items.
|
* with a corresponding list of queue items.
|
||||||
|
* <p>
|
||||||
|
* The {@link PlaybackPreparer} handles the media actions {@code ACTION_PREPARE},
|
||||||
|
* {@code ACTION_PREPARE_FROM_MEDIA_ID}, {@code ACTION_PREPARE_FROM_URI} and
|
||||||
|
* {@code ACTION_PREPARE_FROM_SEARCH}.
|
||||||
*/
|
*/
|
||||||
public interface PlaybackPreparer extends PlaybackActionSupport {
|
public interface PlaybackPreparer extends PlaybackActionSupport {
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onPrepare()}.
|
* See {@link MediaSessionCompat.Callback#onPrepare()}.
|
||||||
*/
|
*/
|
||||||
void onPrepare(ExoPlayer player);
|
void onPrepare();
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onPrepareFromMediaId(String, Bundle)}.
|
* See {@link MediaSessionCompat.Callback#onPrepareFromMediaId(String, Bundle)}.
|
||||||
*/
|
*/
|
||||||
void onPrepareFromMediaId(ExoPlayer player, String mediaId, Bundle extras);
|
void onPrepareFromMediaId(String mediaId, Bundle extras);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onPrepareFromSearch(String, Bundle)}.
|
* See {@link MediaSessionCompat.Callback#onPrepareFromSearch(String, Bundle)}.
|
||||||
*/
|
*/
|
||||||
void onPrepareFromSearch(ExoPlayer player, String query, Bundle extras);
|
void onPrepareFromSearch(String query, Bundle extras);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onPrepareFromUri(Uri, Bundle)}.
|
* See {@link MediaSessionCompat.Callback#onPrepareFromUri(Uri, Bundle)}.
|
||||||
*/
|
*/
|
||||||
void onPrepareFromUri(ExoPlayer player, Uri uri, Bundle extras);
|
void onPrepareFromUri(Uri uri, Bundle extras);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onCommand(String, Bundle, ResultReceiver)}.
|
* See {@link MediaSessionCompat.Callback#onCommand(String, Bundle, ResultReceiver)}.
|
||||||
*/
|
*/
|
||||||
void onCommand(ExoPlayer player, String command, Bundle extras, ResultReceiver cb);
|
void onCommand(String command, Bundle extras, ResultReceiver cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -144,13 +146,13 @@ public final class MediaSessionConnector {
|
||||||
*
|
*
|
||||||
* @param player The player of which the timeline has changed.
|
* @param player The player of which the timeline has changed.
|
||||||
*/
|
*/
|
||||||
void onTimelineChanged(ExoPlayer player);
|
void onTimelineChanged(Player player);
|
||||||
/**
|
/**
|
||||||
* Called when the current window index changed.
|
* Called when the current window index changed.
|
||||||
*
|
*
|
||||||
* @param player The player of which the current window index of the timeline has changed.
|
* @param player The player of which the current window index of the timeline has changed.
|
||||||
*/
|
*/
|
||||||
void onCurrentWindowIndexChanged(ExoPlayer player);
|
void onCurrentWindowIndexChanged(Player player);
|
||||||
/**
|
/**
|
||||||
* Gets the id of the currently active queue item or
|
* Gets the id of the currently active queue item or
|
||||||
* {@link MediaSessionCompat.QueueItem#UNKNOWN_ID} if the active item is unknown.
|
* {@link MediaSessionCompat.QueueItem#UNKNOWN_ID} if the active item is unknown.
|
||||||
|
|
@ -162,23 +164,23 @@ public final class MediaSessionConnector {
|
||||||
* @param player The player connected to the media session.
|
* @param player The player connected to the media session.
|
||||||
* @return The id of the active queue item.
|
* @return The id of the active queue item.
|
||||||
*/
|
*/
|
||||||
long getActiveQueueItemId(@Nullable ExoPlayer player);
|
long getActiveQueueItemId(@Nullable Player player);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onSkipToPrevious()}.
|
* See {@link MediaSessionCompat.Callback#onSkipToPrevious()}.
|
||||||
*/
|
*/
|
||||||
void onSkipToPrevious(ExoPlayer player);
|
void onSkipToPrevious(Player player);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onSkipToQueueItem(long)}.
|
* See {@link MediaSessionCompat.Callback#onSkipToQueueItem(long)}.
|
||||||
*/
|
*/
|
||||||
void onSkipToQueueItem(ExoPlayer player, long id);
|
void onSkipToQueueItem(Player player, long id);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onSkipToNext()}.
|
* See {@link MediaSessionCompat.Callback#onSkipToNext()}.
|
||||||
*/
|
*/
|
||||||
void onSkipToNext(ExoPlayer player);
|
void onSkipToNext(Player player);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onSetShuffleModeEnabled(boolean)}.
|
* See {@link MediaSessionCompat.Callback#onSetShuffleModeEnabled(boolean)}.
|
||||||
*/
|
*/
|
||||||
void onSetShuffleModeEnabled(ExoPlayer player, boolean enabled);
|
void onSetShuffleModeEnabled(Player player, boolean enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -188,25 +190,25 @@ public final class MediaSessionConnector {
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onAddQueueItem(MediaDescriptionCompat description)}.
|
* See {@link MediaSessionCompat.Callback#onAddQueueItem(MediaDescriptionCompat description)}.
|
||||||
*/
|
*/
|
||||||
void onAddQueueItem(ExoPlayer player, MediaDescriptionCompat description);
|
void onAddQueueItem(Player player, MediaDescriptionCompat description);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onAddQueueItem(MediaDescriptionCompat description,
|
* See {@link MediaSessionCompat.Callback#onAddQueueItem(MediaDescriptionCompat description,
|
||||||
* int index)}.
|
* int index)}.
|
||||||
*/
|
*/
|
||||||
void onAddQueueItem(ExoPlayer player, MediaDescriptionCompat description, int index);
|
void onAddQueueItem(Player player, MediaDescriptionCompat description, int index);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onRemoveQueueItem(MediaDescriptionCompat
|
* See {@link MediaSessionCompat.Callback#onRemoveQueueItem(MediaDescriptionCompat
|
||||||
* description)}.
|
* description)}.
|
||||||
*/
|
*/
|
||||||
void onRemoveQueueItem(ExoPlayer player, MediaDescriptionCompat description);
|
void onRemoveQueueItem(Player player, MediaDescriptionCompat description);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onRemoveQueueItemAt(int index)}.
|
* See {@link MediaSessionCompat.Callback#onRemoveQueueItemAt(int index)}.
|
||||||
*/
|
*/
|
||||||
void onRemoveQueueItemAt(ExoPlayer player, int index);
|
void onRemoveQueueItemAt(Player player, int index);
|
||||||
/**
|
/**
|
||||||
* See {@link MediaSessionCompat.Callback#onSetRating(RatingCompat)}.
|
* See {@link MediaSessionCompat.Callback#onSetRating(RatingCompat)}.
|
||||||
*/
|
*/
|
||||||
void onSetRating(ExoPlayer player, RatingCompat rating);
|
void onSetRating(Player player, RatingCompat rating);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -253,7 +255,7 @@ public final class MediaSessionConnector {
|
||||||
private final ExoPlayerEventListener exoPlayerEventListener;
|
private final ExoPlayerEventListener exoPlayerEventListener;
|
||||||
private final MediaSessionCallback mediaSessionCallback;
|
private final MediaSessionCallback mediaSessionCallback;
|
||||||
|
|
||||||
private SimpleExoPlayer player;
|
private Player player;
|
||||||
private CustomActionProvider[] customActionProviders;
|
private CustomActionProvider[] customActionProviders;
|
||||||
private int currentWindowIndex;
|
private int currentWindowIndex;
|
||||||
private long playbackActions;
|
private long playbackActions;
|
||||||
|
|
@ -319,14 +321,17 @@ public final class MediaSessionConnector {
|
||||||
* actions published with the playback state of the session.
|
* actions published with the playback state of the session.
|
||||||
*
|
*
|
||||||
* @param player The player to be connected to the {@code MediaSession}.
|
* @param player The player to be connected to the {@code MediaSession}.
|
||||||
|
* @param playbackPreparer The playback preparer for the player.
|
||||||
* @param customActionProviders Optional {@link CustomActionProvider}s to publish and handle
|
* @param customActionProviders Optional {@link CustomActionProvider}s to publish and handle
|
||||||
* custom actions.
|
* custom actions.
|
||||||
*/
|
*/
|
||||||
public void setPlayer(SimpleExoPlayer player, CustomActionProvider... customActionProviders) {
|
public void setPlayer(Player player, PlaybackPreparer playbackPreparer,
|
||||||
|
CustomActionProvider... customActionProviders) {
|
||||||
if (this.player != null) {
|
if (this.player != null) {
|
||||||
this.player.removeListener(exoPlayerEventListener);
|
this.player.removeListener(exoPlayerEventListener);
|
||||||
mediaSession.setCallback(null);
|
mediaSession.setCallback(null);
|
||||||
}
|
}
|
||||||
|
setPlaybackPreparer(playbackPreparer);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.customActionProviders = (player != null && customActionProviders != null)
|
this.customActionProviders = (player != null && customActionProviders != null)
|
||||||
? customActionProviders : new CustomActionProvider[0];
|
? customActionProviders : new CustomActionProvider[0];
|
||||||
|
|
@ -441,16 +446,7 @@ public final class MediaSessionConnector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void setPlaybackPreparer(PlaybackPreparer playbackPreparer) {
|
||||||
* Sets the {@link PlaybackPreparer} to which preparation commands sent by a media
|
|
||||||
* controller are delegated.
|
|
||||||
* <p>
|
|
||||||
* Required to work properly with Android Auto which requires
|
|
||||||
* {@link PlaybackStateCompat#ACTION_PREPARE_FROM_MEDIA_ID}.
|
|
||||||
*
|
|
||||||
* @param playbackPreparer The preparer to delegate to.
|
|
||||||
*/
|
|
||||||
public void setPlaybackPreparer(PlaybackPreparer playbackPreparer) {
|
|
||||||
if (this.playbackPreparer != null) {
|
if (this.playbackPreparer != null) {
|
||||||
removePlaybackActions(this.playbackPreparer.getSupportedPlaybackActions());
|
removePlaybackActions(this.playbackPreparer.getSupportedPlaybackActions());
|
||||||
}
|
}
|
||||||
|
|
@ -740,7 +736,7 @@ public final class MediaSessionConnector {
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(String command, Bundle extras, ResultReceiver cb) {
|
public void onCommand(String command, Bundle extras, ResultReceiver cb) {
|
||||||
if (playbackPreparer != null) {
|
if (playbackPreparer != null) {
|
||||||
playbackPreparer.onCommand(player, command, extras, cb);
|
playbackPreparer.onCommand(command, extras, cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -749,7 +745,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
playbackPreparer.onPrepare(player);
|
playbackPreparer.onPrepare();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -758,7 +754,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
playbackPreparer.onPrepareFromMediaId(player, mediaId, extras);
|
playbackPreparer.onPrepareFromMediaId(mediaId, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -767,7 +763,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
playbackPreparer.onPrepareFromSearch(player, query, extras);
|
playbackPreparer.onPrepareFromSearch(query, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -776,7 +772,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_URI)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_URI)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
playbackPreparer.onPrepareFromUri(player, uri, extras);
|
playbackPreparer.onPrepareFromUri(uri, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -785,7 +781,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
playbackPreparer.onPrepareFromMediaId(player, mediaId, extras);
|
playbackPreparer.onPrepareFromMediaId(mediaId, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -794,7 +790,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
playbackPreparer.onPrepareFromSearch(player, query, extras);
|
playbackPreparer.onPrepareFromSearch(query, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -803,7 +799,7 @@ public final class MediaSessionConnector {
|
||||||
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_URI)) {
|
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_URI)) {
|
||||||
player.stop();
|
player.stop();
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
playbackPreparer.onPrepareFromUri(player, uri, extras);
|
playbackPreparer.onPrepareFromUri(uri, extras);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.ext.mediasession;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.util.RepeatModeUtil;
|
import com.google.android.exoplayer2.util.RepeatModeUtil;
|
||||||
|
|
||||||
|
|
@ -32,7 +31,7 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
|
||||||
private static final int DEFAULT_REPEAT_MODES = RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE
|
private static final int DEFAULT_REPEAT_MODES = RepeatModeUtil.REPEAT_TOGGLE_MODE_ONE
|
||||||
| RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL;
|
| RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL;
|
||||||
|
|
||||||
private final ExoPlayer player;
|
private final Player player;
|
||||||
@RepeatModeUtil.RepeatToggleModes
|
@RepeatModeUtil.RepeatToggleModes
|
||||||
private final int repeatToggleModes;
|
private final int repeatToggleModes;
|
||||||
private final CharSequence repeatAllDescription;
|
private final CharSequence repeatAllDescription;
|
||||||
|
|
@ -48,7 +47,7 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
|
||||||
* @param context The context.
|
* @param context The context.
|
||||||
* @param player The player on which to toggle the repeat mode.
|
* @param player The player on which to toggle the repeat mode.
|
||||||
*/
|
*/
|
||||||
public RepeatModeActionProvider(Context context, ExoPlayer player) {
|
public RepeatModeActionProvider(Context context, Player player) {
|
||||||
this(context, player, DEFAULT_REPEAT_MODES);
|
this(context, player, DEFAULT_REPEAT_MODES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,7 +58,7 @@ public final class RepeatModeActionProvider implements MediaSessionConnector.Cus
|
||||||
* @param player The player on which to toggle the repeat mode.
|
* @param player The player on which to toggle the repeat mode.
|
||||||
* @param repeatToggleModes The toggle modes to enable.
|
* @param repeatToggleModes The toggle modes to enable.
|
||||||
*/
|
*/
|
||||||
public RepeatModeActionProvider(Context context, ExoPlayer player,
|
public RepeatModeActionProvider(Context context, Player player,
|
||||||
@RepeatModeUtil.RepeatToggleModes int repeatToggleModes) {
|
@RepeatModeUtil.RepeatToggleModes int repeatToggleModes) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.repeatToggleModes = repeatToggleModes;
|
this.repeatToggleModes = repeatToggleModes;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import android.support.v4.media.MediaDescriptionCompat;
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
import android.support.v4.media.session.MediaSessionCompat;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract implementation of the {@link MediaSessionConnector.QueueNavigator} that's based on an
|
* An abstract implementation of the {@link MediaSessionConnector.QueueNavigator} that's based on an
|
||||||
* {@link ExoPlayer}'s current {@link Timeline} and maps the timeline of the player to the media
|
* {@link Player}'s current {@link Timeline} and maps the timeline of the player to the media
|
||||||
* session queue.
|
* session queue.
|
||||||
*/
|
*/
|
||||||
public abstract class TimelineQueueNavigator implements MediaSessionConnector.QueueNavigator {
|
public abstract class TimelineQueueNavigator implements MediaSessionConnector.QueueNavigator {
|
||||||
|
|
@ -87,22 +87,22 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimelineChanged(ExoPlayer player) {
|
public void onTimelineChanged(Player player) {
|
||||||
publishFloatingQueueWindow(player);
|
publishFloatingQueueWindow(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCurrentWindowIndexChanged(ExoPlayer player) {
|
public void onCurrentWindowIndexChanged(Player player) {
|
||||||
publishFloatingQueueWindow(player);
|
publishFloatingQueueWindow(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final long getActiveQueueItemId(@Nullable ExoPlayer player) {
|
public final long getActiveQueueItemId(@Nullable Player player) {
|
||||||
return activeQueueItemId;
|
return activeQueueItemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSkipToPrevious(ExoPlayer player) {
|
public final void onSkipToPrevious(Player player) {
|
||||||
Timeline timeline = player.getCurrentTimeline();
|
Timeline timeline = player.getCurrentTimeline();
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -118,7 +118,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSkipToQueueItem(ExoPlayer player, long id) {
|
public final void onSkipToQueueItem(Player player, long id) {
|
||||||
Timeline timeline = player.getCurrentTimeline();
|
Timeline timeline = player.getCurrentTimeline();
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -130,7 +130,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onSkipToNext(ExoPlayer player) {
|
public final void onSkipToNext(Player player) {
|
||||||
Timeline timeline = player.getCurrentTimeline();
|
Timeline timeline = player.getCurrentTimeline();
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -143,11 +143,11 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetShuffleModeEnabled(ExoPlayer player, boolean enabled) {
|
public void onSetShuffleModeEnabled(Player player, boolean enabled) {
|
||||||
// TODO: Implement this.
|
// TODO: Implement this.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void publishFloatingQueueWindow(ExoPlayer player) {
|
private void publishFloatingQueueWindow(Player player) {
|
||||||
if (player.getCurrentTimeline().isEmpty()) {
|
if (player.getCurrentTimeline().isEmpty()) {
|
||||||
mediaSession.setQueue(Collections.<MediaSessionCompat.QueueItem>emptyList());
|
mediaSession.setQueue(Collections.<MediaSessionCompat.QueueItem>emptyList());
|
||||||
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
|
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue