[Android] [PATCH 2/3] Video: add mute control from keyboard

Alexandre Perraud 4leyx4ndre at gmail.com
Thu Sep 25 17:19:27 CEST 2014


---
 vlc-android/res/values/strings.xml                  |  2 ++
 .../videolan/vlc/gui/video/VideoPlayerActivity.java | 21 ++++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index ed70538..5c7b0f2 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -114,6 +114,8 @@
     <string name="track_codec_info">Codec: %1$s\n</string>
     <string name="track_language_info">Language: %1$s\n</string>
     <string name="volume">Volume</string>
+    <string name="sound_on">Sound On</string>
+    <string name="sound_off">Sound Off</string>
     <string name="brightness">Brightness</string>
 
     <plurals name="track_channels_info_quantity">
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 79fc2db..75cc98d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -206,6 +206,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     private AudioManager mAudioManager;
     private int mAudioMax;
     private OnAudioFocusChangeListener mAudioFocusListener;
+    private boolean mMute = false;
+    private int mVol, mVolSave;
 
     //Touch Events
     private static final int TOUCH_NONE = 0;
@@ -214,7 +216,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     private static final int TOUCH_SEEK = 3;
     private int mTouchAction;
     private int mSurfaceYDisplayRange;
-    private float mTouchY, mTouchX, mVol;
+    private float mTouchY, mTouchX;
 
     // Brightness
     private boolean mIsFirstBrightnessGesture = true;
@@ -698,6 +700,9 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         case KeyEvent.KEYCODE_A:
             mSize.performClick();
             return true;
+        case KeyEvent.KEYCODE_VOLUME_MUTE:
+            updateMute();
+            return true;
         case KeyEvent.KEYCODE_S:
         case KeyEvent.KEYCODE_MEDIA_STOP:
             finish();
@@ -1340,6 +1345,20 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         }
     }
 
+    private void updateMute () {
+        if (!mMute) {
+            mVolSave = mVol;
+            mMute = true;
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
+            showInfo(R.string.sound_off,1000);
+        } else {
+            mVol = mVolSave;
+            mMute = false;
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mVol, 0);
+            showInfo(R.string.sound_on,1000);
+        }
+    }
+
     private void initBrightnessTouch() {
         float brightnesstemp = 0.01f;
         // Initialize the layoutParams screen brightness
-- 
1.9.1



More information about the Android mailing list