[Android] Catch SecurityException on volume change
Geoffrey Métais
git at videolan.org
Wed Oct 4 14:40:05 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 4 14:38:17 2017 +0200| [515d38b62d7a82e8198749d31670ac720d02c39f] | committer: Geoffrey Métais
Catch SecurityException on volume change
Some device may throw a SecurityException when we ask for volume change.
Maybe related to 'Do not Disturb' mode.
> https://code.videolan.org/videolan/vlc-android/commit/515d38b62d7a82e8198749d31670ac720d02c39f
---
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 715fa3c3e..2f2c8ebb0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2290,10 +2290,12 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if (vol <= mAudioMax) {
mService.setVolume(100);
if (vol != mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)) {
- mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);
- // High Volume warning can block volume setting
- if (mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) != vol)
- mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, AudioManager.FLAG_SHOW_UI);
+ try {
+ mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);
+ // High Volume warning can block volume setting
+ if (mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) != vol)
+ mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, AudioManager.FLAG_SHOW_UI);
+ } catch (SecurityException ignored) {} //Some device won't allow us to change volume
}
vol = Math.round(vol * 100 / mAudioMax);
} else {
More information about the Android
mailing list