Skip to content

Commit

Permalink
Add EventListener.onPlaybackSuppressionReasonChanged
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tonihei authored and ojw28 committed Oct 2, 2019
1 parent 60a9cf6 commit 004b9e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,21 @@ public void setPlayWhenReady(
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ default void onLoadingChanged(boolean isLoading) {}
*/
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.
*
Expand Down

0 comments on commit 004b9e8

Please sign in to comment.