From 1264dbcd36935629f289594b89443abd7b0c57fc Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Fri, 23 Oct 2020 14:50:03 +0100 Subject: [PATCH] Handle stream volume register/unregister errors Issue: #8106 Issue: #8087 PiperOrigin-RevId: 338664455 --- RELEASENOTES.md | 16 ++++++++--- .../exoplayer2/StreamVolumeManager.java | 27 +++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 5a5aa126558..e8daab543f0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,12 @@ # Release notes +### 2.12.2 (2020-11-??) ### + +* Core library: + * Suppress exceptions from registering/unregistering the stream volume + receiver ([#8087](https://github.com/google/ExoPlayer/issues/8087)), + ([#8106](https://github.com/google/ExoPlayer/issues/8106)). + ### 2.12.1 (2020-10-23) ### * Core library: @@ -7,6 +14,7 @@ argument ([#8024](https://github.com/google/ExoPlayer/issues/8024)). * Fix bug where streams with highly uneven track durations may get stuck in a buffering state + ([#7943](https://github.com/google/ExoPlayer/issues/7943)). * Switch Guava dependency from `implementation` to `api` ([#7905](https://github.com/google/ExoPlayer/issues/7905), [#7993](https://github.com/google/ExoPlayer/issues/7993)). @@ -63,9 +71,9 @@ * Allow apps to specify a `VideoAdPlayerCallback` ([#7944](https://github.com/google/ExoPlayer/issues/7944)). * Accept ad tags via the `AdsMediaSource` constructor and deprecate - passing them via the `ImaAdsLoader` constructor/builders. Passing the - ad tag via media item playback properties continues to be supported. - This is in preparation for supporting ads in playlists + passing them via the `ImaAdsLoader` constructor/builders. Passing the ad + tag via media item playback properties continues to be supported. This + is in preparation for supporting ads in playlists ([#3750](https://github.com/google/ExoPlayer/issues/3750)). * Add a way to override ad media MIME types ([#7961)(https://github.com/google/ExoPlayer/issues/7961)). @@ -74,6 +82,8 @@ * Upgrade IMA SDK dependency to 3.20.1. This brings in a fix for companion ads rendering when targeting API 29 ([#6432](https://github.com/google/ExoPlayer/issues/6432)). +* Metadata retriever: + * Parse Google Photos HEIC motion photos metadata. ### 2.12.0 (2020-09-11) ### diff --git a/library/core/src/main/java/com/google/android/exoplayer2/StreamVolumeManager.java b/library/core/src/main/java/com/google/android/exoplayer2/StreamVolumeManager.java index 66216de8617..fa5d316b60b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/StreamVolumeManager.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/StreamVolumeManager.java @@ -21,7 +21,9 @@ import android.content.IntentFilter; import android.media.AudioManager; import android.os.Handler; +import androidx.annotation.Nullable; import com.google.android.exoplayer2.util.Assertions; +import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Util; /** A manager that wraps {@link AudioManager} to control/listen audio stream volume. */ @@ -37,6 +39,8 @@ public interface Listener { void onStreamVolumeChanged(int streamVolume, boolean streamMuted); } + private static final String TAG = "StreamVolumeManager"; + // TODO(b/151280453): Replace the hidden intent action with an official one. // Copied from AudioManager#VOLUME_CHANGED_ACTION private static final String VOLUME_CHANGED_ACTION = "android.media.VOLUME_CHANGED_ACTION"; @@ -48,12 +52,11 @@ public interface Listener { private final Handler eventHandler; private final Listener listener; private final AudioManager audioManager; - private final VolumeChangeReceiver receiver; + @Nullable private VolumeChangeReceiver receiver; @C.StreamType private int streamType; private int volume; private boolean muted; - private boolean released; /** Creates a manager. */ public StreamVolumeManager(Context context, Handler eventHandler, Listener listener) { @@ -68,9 +71,14 @@ public StreamVolumeManager(Context context, Handler eventHandler, Listener liste volume = getVolumeFromManager(audioManager, streamType); muted = getMutedFromManager(audioManager, streamType); - receiver = new VolumeChangeReceiver(); + VolumeChangeReceiver receiver = new VolumeChangeReceiver(); IntentFilter filter = new IntentFilter(VOLUME_CHANGED_ACTION); - applicationContext.registerReceiver(receiver, filter); + try { + applicationContext.registerReceiver(receiver, filter); + this.receiver = receiver; + } catch (RuntimeException e) { + Log.w(TAG, "Error registering stream volume receiver", e); + } } /** Sets the audio stream type. */ @@ -159,11 +167,14 @@ public void setMuted(boolean muted) { /** Releases the manager. It must be called when the manager is no longer required. */ public void release() { - if (released) { - return; + if (receiver != null) { + try { + applicationContext.unregisterReceiver(receiver); + } catch (RuntimeException e) { + Log.w(TAG, "Error unregistering stream volume receiver", e); + } + receiver = null; } - applicationContext.unregisterReceiver(receiver); - released = true; } private void updateVolumeAndNotifyIfChanged() {