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

Alexandre Perraud 4leyx4ndre at gmail.com
Wed Oct 1 17:38:53 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 c336779..f5f7180 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -113,6 +113,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 9d3e32d..4ff2fa2 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:
             resizeVideo();
             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