[Android] [PATCH 1/2] Generate audio session id in VLCOptions for libVLC

Alexandre Janniaux alexandre.janniaux at gmail.com
Thu Feb 22 15:46:19 CET 2018


Generate an audio session id from AudioManager and pass it to libVLC as
a command line argument so that it creates AudioTrack in this session.
---
 vlc-android/src/org/videolan/vlc/util/VLCOptions.java | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 46b2f72aa..a1c5ad4af 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -22,6 +22,8 @@ package org.videolan.vlc.util;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.media.AudioManager;
+import android.os.Build;
 import android.preference.PreferenceManager;
 import android.support.annotation.MainThread;
 import android.util.Log;
@@ -52,11 +54,19 @@ public class VLCOptions {
     public static final int HW_ACCELERATION_DECODING = 1;
     public static final int HW_ACCELERATION_FULL = 2;
 
+    private static int AUDIOTRACK_SESSION_ID = 0;
+
     // TODO should return List<String>
     public static ArrayList<String> getLibOptions() {
         final Context context = VLCApplication.getAppContext();
         final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
 
+        /* generate an audio session id so as to share audio output with external equalizer */
+        if (Build.VERSION.SDK_INT >= 21 && AUDIOTRACK_SESSION_ID == 0) {
+            AudioManager audioManager = context.getSystemService(AudioManager.class);
+            AUDIOTRACK_SESSION_ID = audioManager.generateAudioSessionId();
+        }
+
         ArrayList<String> options = new ArrayList<String>(50);
 
         final boolean timeStrechingDefault = VLCApplication.getAppResources().getBoolean(R.bool.time_stretching_default);
@@ -103,6 +113,7 @@ public class VLCOptions {
         options.add(chroma);
         options.add("--audio-resampler");
         options.add(getResampler());
+        options.add("--audiotrack-session-id=" + AUDIOTRACK_SESSION_ID);
 
         options.add("--freetype-rel-fontsize=" + freetypeRelFontsize);
         if (freetypeBold)
@@ -323,4 +334,10 @@ public class VLCOptions {
         return PreferenceManager.getDefaultSharedPreferences(context)
                 .getBoolean("equalizer_enabled", false);
     }
+
+    public static int getAudiotrackSessionId() {
+        if (Build.VERSION.SDK_INT < 21)
+            return 0;
+        return AUDIOTRACK_SESSION_ID;
+    }
 }
-- 
2.16.1



More information about the Android mailing list