Skip to content

Commit

Permalink
Work around AudioManager#getStreamVolume crashes
Browse files Browse the repository at this point in the history
#minor-release
Issue:#8191
PiperOrigin-RevId: 341632732
  • Loading branch information
kim-vde committed Nov 11, 2020
1 parent 363693d commit 4ae0401
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
([#7882](https://github.com/google/ExoPlayer/issues/7882)).
* Audio:
* Retry playback after some types of `AudioTrack` error.
* Work around `AudioManager` crashes when calling `getStreamVolume`
([#8191](https://github.com/google/ExoPlayer/issues/8191)).
* Extractors:
* Matroska: Add support for 32-bit floating point PCM, and 8-bit and
16-bit big endian integer PCM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,22 @@ private void updateVolumeAndNotifyIfChanged() {
}

private static int getVolumeFromManager(AudioManager audioManager, @C.StreamType int streamType) {
return audioManager.getStreamVolume(streamType);
// AudioManager#getStreamVolume(int) throws an exception on some devices. See
// https://github.com/google/ExoPlayer/issues/8191.
try {
return audioManager.getStreamVolume(streamType);
} catch (RuntimeException e) {
Log.w(TAG, "Could not retrieve stream volume for stream type " + streamType, e);
return audioManager.getStreamMaxVolume(streamType);
}
}

private static boolean getMutedFromManager(
AudioManager audioManager, @C.StreamType int streamType) {
if (Util.SDK_INT >= 23) {
return audioManager.isStreamMute(streamType);
} else {
return audioManager.getStreamVolume(streamType) == 0;
return getVolumeFromManager(audioManager, streamType) == 0;
}
}

Expand Down

0 comments on commit 4ae0401

Please sign in to comment.