[Android] VideoPlayer: activate hdmi audio if available

Thomas Guillem git at videolan.org
Wed Apr 8 09:35:46 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Apr  7 11:37:01 2015 +0200| [d72c9aed0ecf23f4038cfff901a429d88e7fb4c3] | committer: Thomas Guillem

VideoPlayer: activate hdmi audio if available

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

 .../vlc/gui/video/VideoPlayerActivity.java         |   28 ++++++++++++++++++++
 .../src/org/videolan/vlc/util/VLCInstance.java     |    7 +++++
 2 files changed, 35 insertions(+)

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 d2386d2..0527e82 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -311,6 +311,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     private OnLayoutChangeListener mOnLayoutChangeListener;
     private AlertDialog mAlertDialog;
 
+    private boolean mHasHdmiAudio = false;
+
     @Override
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
     protected void onCreate(Bundle savedInstanceState) {
@@ -475,6 +477,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
             filter.addAction(Intent.ACTION_BATTERY_CHANGED);
         filter.addAction(VLCApplication.SLEEP_INTENT);
         registerReceiver(mReceiver, filter);
+        if (mReceiverV21 != null)
+            registerV21();
 
         Log.d(TAG,
                 "Hardware acceleration mode: "
@@ -582,6 +586,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         super.onDestroy();
         if (mReceiver != null)
             unregisterReceiver(mReceiver);
+        if (mReceiverV21 != null)
+            unregisterReceiver(mReceiverV21);
 
         mAudioManager = null;
     }
@@ -839,6 +845,27 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         }
     };
 
+    @TargetApi(21)
+    private void registerV21() {
+        final IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_HDMI_AUDIO_PLUG);
+        registerReceiver(mReceiverV21, intentFilter);
+    }
+
+    private final BroadcastReceiver mReceiverV21 = LibVlcUtil.isLolliPopOrLater() ? new BroadcastReceiver()
+    {
+        @TargetApi(21)
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (action == null)
+                return;
+            if (action.equalsIgnoreCase(AudioManager.ACTION_HDMI_AUDIO_PLUG)) {
+                mHasHdmiAudio = true;
+                Log.d(TAG, "has hdmi audio");
+            }
+        }
+    } : null;
+
     @Override
     public boolean onTrackballEvent(MotionEvent event) {
         showOverlay();
@@ -2712,6 +2739,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
             }
 
             // Start playback & seek
+            VLCInstance.setAudioHdmiEnabled(this, mHasHdmiAudio);
             mMediaListPlayer.playIndex(savedIndexPosition, wasPaused);
             seek(intentPosition, mediaLength);
 
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
index 547580b..cea57d9 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
@@ -144,4 +144,11 @@ public class VLCInstance {
         sLibVLC.setHardwareAcceleration(hardwareAcceleration);
         sLibVLC.setDevHardwareDecoder(devHardwareDecoder);
     }
+
+    public static synchronized void setAudioHdmiEnabled(Context context, boolean enabled) {
+        if (sLibVLC != null && sLibVLC.isHdmiAudioEnabled() != enabled) {
+            sLibVLC.setHdmiAudioEnabled(enabled);
+            restart(context);
+        }
+    }
 }



More information about the Android mailing list