Support setPlaybackSpeed(float) with the MediaSessionConnector
Issue: #8229 #exofixit PiperOrigin-RevId: 346968046
This commit is contained in:
parent
4ee02a27de
commit
2ee40270e5
@ -116,6 +116,10 @@
|
|||||||
* Notify onBufferingEnded when the state of origin player becomes
|
* Notify onBufferingEnded when the state of origin player becomes
|
||||||
`STATE_IDLE` or `STATE_ENDED`.
|
`STATE_IDLE` or `STATE_ENDED`.
|
||||||
* Allow to remove all playlist items that makes the player reset.
|
* Allow to remove all playlist items that makes the player reset.
|
||||||
|
* MediaSession extension:
|
||||||
|
* Support `setPlaybackSpeed(float)` and disable it by default. Use
|
||||||
|
`MediaSessionConnector.setEnabledPlaybackActions(long)` to enable
|
||||||
|
([#8229](https://github.com/google/ExoPlayer/issues/8229)).
|
||||||
|
|
||||||
### 2.12.1 (2020-10-23) ###
|
### 2.12.1 (2020-10-23) ###
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ project.ext {
|
|||||||
androidxAnnotationVersion = '1.1.0'
|
androidxAnnotationVersion = '1.1.0'
|
||||||
androidxAppCompatVersion = '1.1.0'
|
androidxAppCompatVersion = '1.1.0'
|
||||||
androidxCollectionVersion = '1.1.0'
|
androidxCollectionVersion = '1.1.0'
|
||||||
androidxMediaVersion = '1.0.1'
|
androidxMediaVersion = '1.2.1'
|
||||||
androidxMultidexVersion = '2.0.0'
|
androidxMultidexVersion = '2.0.0'
|
||||||
androidxRecyclerViewVersion = '1.1.0'
|
androidxRecyclerViewVersion = '1.1.0'
|
||||||
androidxTestCoreVersion = '1.3.0'
|
androidxTestCoreVersion = '1.3.0'
|
||||||
|
@ -101,6 +101,10 @@ public final class MediaSessionConnector {
|
|||||||
ExoPlayerLibraryInfo.registerModule("goog.exo.mediasession");
|
ExoPlayerLibraryInfo.registerModule("goog.exo.mediasession");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Indicates this session supports the set playback speed command. */
|
||||||
|
// TODO(b/174297519) Replace with PlaybackStateCompat.ACTION_SET_PLAYBACK_SPEED when released.
|
||||||
|
public static final long ACTION_SET_PLAYBACK_SPEED = 1 << 22;
|
||||||
|
|
||||||
/** Playback actions supported by the connector. */
|
/** Playback actions supported by the connector. */
|
||||||
@LongDef(
|
@LongDef(
|
||||||
flag = true,
|
flag = true,
|
||||||
@ -113,7 +117,8 @@ public final class MediaSessionConnector {
|
|||||||
PlaybackStateCompat.ACTION_REWIND,
|
PlaybackStateCompat.ACTION_REWIND,
|
||||||
PlaybackStateCompat.ACTION_STOP,
|
PlaybackStateCompat.ACTION_STOP,
|
||||||
PlaybackStateCompat.ACTION_SET_REPEAT_MODE,
|
PlaybackStateCompat.ACTION_SET_REPEAT_MODE,
|
||||||
PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
|
PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE,
|
||||||
|
ACTION_SET_PLAYBACK_SPEED
|
||||||
})
|
})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface PlaybackActions {}
|
public @interface PlaybackActions {}
|
||||||
@ -128,10 +133,13 @@ public final class MediaSessionConnector {
|
|||||||
| PlaybackStateCompat.ACTION_REWIND
|
| PlaybackStateCompat.ACTION_REWIND
|
||||||
| PlaybackStateCompat.ACTION_STOP
|
| PlaybackStateCompat.ACTION_STOP
|
||||||
| PlaybackStateCompat.ACTION_SET_REPEAT_MODE
|
| PlaybackStateCompat.ACTION_SET_REPEAT_MODE
|
||||||
| PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE;
|
| PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
|
||||||
|
| ACTION_SET_PLAYBACK_SPEED;
|
||||||
|
|
||||||
/** The default playback actions. */
|
/** The default playback actions. */
|
||||||
@PlaybackActions public static final long DEFAULT_PLAYBACK_ACTIONS = ALL_PLAYBACK_ACTIONS;
|
@PlaybackActions
|
||||||
|
public static final long DEFAULT_PLAYBACK_ACTIONS =
|
||||||
|
ALL_PLAYBACK_ACTIONS - ACTION_SET_PLAYBACK_SPEED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the {@link PlaybackStateCompat} float extra with the value of {@code
|
* The name of the {@link PlaybackStateCompat} float extra with the value of {@code
|
||||||
@ -145,7 +153,8 @@ public final class MediaSessionConnector {
|
|||||||
| PlaybackStateCompat.ACTION_PAUSE
|
| PlaybackStateCompat.ACTION_PAUSE
|
||||||
| PlaybackStateCompat.ACTION_STOP
|
| PlaybackStateCompat.ACTION_STOP
|
||||||
| PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
|
| PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
|
||||||
| PlaybackStateCompat.ACTION_SET_REPEAT_MODE;
|
| PlaybackStateCompat.ACTION_SET_REPEAT_MODE
|
||||||
|
| ACTION_SET_PLAYBACK_SPEED;
|
||||||
private static final int BASE_MEDIA_SESSION_FLAGS =
|
private static final int BASE_MEDIA_SESSION_FLAGS =
|
||||||
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
|
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
|
||||||
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS;
|
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS;
|
||||||
@ -1230,6 +1239,14 @@ public final class MediaSessionConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSetPlaybackSpeed(float speed) {
|
||||||
|
if (canDispatchPlaybackAction(ACTION_SET_PLAYBACK_SPEED) && speed > 0) {
|
||||||
|
controlDispatcher.dispatchSetPlaybackParameters(
|
||||||
|
player, player.getPlaybackParameters().withSpeed(speed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSkipToNext() {
|
public void onSkipToNext() {
|
||||||
if (canDispatchToQueueNavigator(PlaybackStateCompat.ACTION_SKIP_TO_NEXT)) {
|
if (canDispatchToQueueNavigator(PlaybackStateCompat.ACTION_SKIP_TO_NEXT)) {
|
||||||
|
@ -113,6 +113,15 @@ public interface ControlDispatcher {
|
|||||||
*/
|
*/
|
||||||
boolean dispatchStop(Player player, boolean reset);
|
boolean dispatchStop(Player player, boolean reset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches a {@link Player#setPlaybackParameters(PlaybackParameters)} operation.
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to which the operation should be dispatched.
|
||||||
|
* @param playbackParameters The playback parameters.
|
||||||
|
* @return True if the operation was dispatched. False if suppressed.
|
||||||
|
*/
|
||||||
|
boolean dispatchSetPlaybackParameters(Player player, PlaybackParameters playbackParameters);
|
||||||
|
|
||||||
/** Returns {@code true} if rewind is enabled, {@code false} otherwise. */
|
/** Returns {@code true} if rewind is enabled, {@code false} otherwise. */
|
||||||
boolean isRewindEnabled();
|
boolean isRewindEnabled();
|
||||||
|
|
||||||
|
@ -139,6 +139,13 @@ public class DefaultControlDispatcher implements ControlDispatcher {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchSetPlaybackParameters(
|
||||||
|
Player player, PlaybackParameters playbackParameters) {
|
||||||
|
player.setPlaybackParameters(playbackParameters);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRewindEnabled() {
|
public boolean isRewindEnabled() {
|
||||||
return rewindIncrementMs > 0;
|
return rewindIncrementMs > 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user