mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add EventListener.onPlaybackSuppressionReasonChanged
Adding this callback makes sense for completeness (we have similar callbacks for all other playback state properties), and also to detect audio focus loss while buffering which would currently trigger no callback because isPlaying is still false. Issue:#6203 PiperOrigin-RevId: 271347351
This commit is contained in:
parent
60a9cf68c9
commit
004b9e8e8c
@ -66,6 +66,9 @@
|
||||
([#6161](https://github.com/google/ExoPlayer/issues/6161)).
|
||||
* Add demo app to show how to use the Android 10 `SurfaceControl` API with
|
||||
ExoPlayer ([#677](https://github.com/google/ExoPlayer/issues/677)).
|
||||
* Add `Player.onPlaybackSuppressionReasonChanged` to allow listeners to
|
||||
detect playbacks suppressions (e.g. audio focus loss) directly
|
||||
([#6203](https://github.com/google/ExoPlayer/issues/6203)).
|
||||
|
||||
### 2.10.5 (2019-09-20) ###
|
||||
|
||||
|
@ -264,17 +264,21 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
internalPlayer.setPlayWhenReady(internalPlayWhenReady);
|
||||
}
|
||||
boolean playWhenReadyChanged = this.playWhenReady != playWhenReady;
|
||||
boolean suppressionReasonChanged = this.playbackSuppressionReason != playbackSuppressionReason;
|
||||
this.playWhenReady = playWhenReady;
|
||||
this.playbackSuppressionReason = playbackSuppressionReason;
|
||||
boolean isPlaying = isPlaying();
|
||||
boolean isPlayingChanged = oldIsPlaying != isPlaying;
|
||||
if (playWhenReadyChanged || isPlayingChanged) {
|
||||
if (playWhenReadyChanged || suppressionReasonChanged || isPlayingChanged) {
|
||||
int playbackState = playbackInfo.playbackState;
|
||||
notifyListeners(
|
||||
listener -> {
|
||||
if (playWhenReadyChanged) {
|
||||
listener.onPlayerStateChanged(playWhenReady, playbackState);
|
||||
}
|
||||
if (suppressionReasonChanged) {
|
||||
listener.onPlaybackSuppressionReasonChanged(playbackSuppressionReason);
|
||||
}
|
||||
if (isPlayingChanged) {
|
||||
listener.onIsPlayingChanged(isPlaying);
|
||||
}
|
||||
|
@ -392,6 +392,14 @@ public interface Player {
|
||||
*/
|
||||
default void onPlayerStateChanged(boolean playWhenReady, @State int playbackState) {}
|
||||
|
||||
/**
|
||||
* Called when the value returned from {@link #getPlaybackSuppressionReason()} changes.
|
||||
*
|
||||
* @param playbackSuppressionReason The current {@link PlaybackSuppressionReason}.
|
||||
*/
|
||||
default void onPlaybackSuppressionReasonChanged(
|
||||
@PlaybackSuppressionReason int playbackSuppressionReason) {}
|
||||
|
||||
/**
|
||||
* Called when the value of {@link #isPlaying()} changes.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user