Skip to content

Commit

Permalink
Handle stream volume register/unregister errors
Browse files Browse the repository at this point in the history
Issue: #8106
Issue: #8087
PiperOrigin-RevId: 338664455
  • Loading branch information
andrewlewis authored and icbaker committed Nov 18, 2020
1 parent da663aa commit 1264dbc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
16 changes: 13 additions & 3 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# 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:
* Fix issue where `Player.setMediaItems` would ignore its `resetPosition`
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)).
Expand Down Expand Up @@ -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)).
Expand All @@ -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) ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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";
Expand All @@ -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) {
Expand All @@ -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. */
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1264dbc

Please sign in to comment.