[Android] Video: add mute control from keyboard

Alexandre Perraud git at videolan.org
Thu Oct 2 10:21:18 CEST 2014


vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Wed Oct  1 17:38:53 2014 +0200| [1ddc7605a9db7d25b3e0a0114a280758b1092ec4] | committer: Jean-Baptiste Kempf

Video: add mute control from keyboard

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=1ddc7605a9db7d25b3e0a0114a280758b1092ec4
---

 vlc-android/res/values/strings.xml                 |    2 ++
 .../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 c14a4be..057412f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -210,6 +210,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;
@@ -218,7 +220,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;
@@ -727,6 +729,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();
@@ -1369,6 +1374,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



More information about the Android mailing list