[Android] Libvlc: set aout from MediaPlayer and not from LibVLC

Thomas Guillem git at videolan.org
Fri Jun 26 10:06:57 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Jun 26 09:40:21 2015 +0200| [abd7fd5857170cb8142a7d16290e9c5f3d5d8814] | committer: Thomas Guillem

Libvlc: set aout from MediaPlayer and not from LibVLC

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

 libvlc/jni/libvlcjni-mediaplayer.c                 |   24 ++++++++++++++++++++
 libvlc/src/org/videolan/libvlc/MediaPlayer.java    |    5 ++++
 .../src/org/videolan/vlc/util/VLCInstance.java     |    3 +++
 .../src/org/videolan/vlc/util/VLCOptions.java      |   19 +++++++---------
 4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/libvlc/jni/libvlcjni-mediaplayer.c b/libvlc/jni/libvlcjni-mediaplayer.c
index fb93295..3705c62 100644
--- a/libvlc/jni/libvlcjni-mediaplayer.c
+++ b/libvlc/jni/libvlcjni-mediaplayer.c
@@ -635,3 +635,27 @@ Java_org_videolan_libvlc_MediaPlayer_navigate(JNIEnv *env, jobject thiz,
 
     libvlc_media_player_navigate(p_obj->u.p_mp, (unsigned) navigate);
 }
+
+jboolean
+Java_org_videolan_libvlc_MediaPlayer_nativeSetAudioOutput(JNIEnv *env,
+                                                          jobject thiz,
+                                                          jstring jaout)
+{
+    const char* psz_aout;
+    int i_ret;
+    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
+
+    if (!p_obj)
+        return false;
+
+    if (!jaout || !(psz_aout = (*env)->GetStringUTFChars(env, jaout, 0)))
+    {
+        throw_IllegalArgumentException(env, "aout invalid");
+        return false;
+    }
+
+    i_ret = libvlc_audio_output_set(p_obj->u.p_mp, psz_aout);
+    (*env)->ReleaseStringUTFChars(env, jaout, psz_aout);
+
+    return i_ret == 0 ? true : false;
+}
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 66029e6..dd3e754 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -188,6 +188,10 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow
         nativeSetVideoTitleDisplay(position, timeout);
     }
 
+    public synchronized boolean setAudioOutput(String aout) {
+        return nativeSetAudioOutput(aout);
+    }
+
     /**
      * TODO: this doesn't respect API
      *
@@ -346,4 +350,5 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow
     private native void nativeStop();
     private native void nativeSetVideoTitleDisplay(int position, int timeout);
     private native void nativeSetEqualizer(float[] bands);
+    private native boolean nativeSetAudioOutput(String aout);
 }
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
index 0663e66..52229be 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
@@ -70,7 +70,10 @@ public class VLCInstance {
         if (sMediaPlayer == null) {
             if (sLibVLC == null)
                 get();
+            final Context context = VLCApplication.getAppContext();
+            final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
             sMediaPlayer = new MediaPlayer(sLibVLC);
+            sMediaPlayer.setAudioOutput(VLCOptions.getAout(pref));
         }
         return sMediaPlayer;
     }
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 75b9dfc..a07d91e 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -69,13 +69,6 @@ public class VLCOptions {
         if (pref.getBoolean("equalizer_enabled", false))
             setEqualizer(Preferences.getFloatArray(pref, "equalizer_values"));
 
-        int aout = -1;
-        try {
-            aout = Integer.parseInt(pref.getString("aout", "-1"));
-        } catch (NumberFormatException nfe) {
-        }
-        aout = getAout(aout);
-
         int deblocking = -1;
         try {
             deblocking = getDeblocking(Integer.parseInt(pref.getString("deblocking", "-1")));
@@ -102,7 +95,6 @@ public class VLCOptions {
         /* XXX: why can't the default be fine ? #7792 */
         if (networkCaching > 0)
             options.add("--network-caching=" + networkCaching);
-        options.add(aout == AOUT_OPENSLES ? "--aout=opensles" : (aout == AOUT_AUDIOTRACK ? "--aout=android_audiotrack" : "--aout=dummy"));
         options.add("--androidwindow-chroma");
         options.add(chroma.indexOf(0) != 0 ? chroma : "RV32");
 
@@ -115,12 +107,17 @@ public class VLCOptions {
         return options;
     }
 
-    private static int getAout(int aout) {
+    public static String getAout(SharedPreferences pref) {
+        int aout = -1;
+        try {
+            aout = Integer.parseInt(pref.getString("aout", "-1"));
+        } catch (NumberFormatException nfe) {
+        }
         final HWDecoderUtil.AudioOutput hwaout = HWDecoderUtil.getAudioOutputFromDevice();
         if (hwaout == HWDecoderUtil.AudioOutput.AUDIOTRACK || hwaout == HWDecoderUtil.AudioOutput.OPENSLES)
-            return hwaout == HWDecoderUtil.AudioOutput.OPENSLES ? AOUT_OPENSLES : AOUT_AUDIOTRACK;
+            aout = hwaout == HWDecoderUtil.AudioOutput.OPENSLES ? AOUT_OPENSLES : AOUT_AUDIOTRACK;
 
-        return aout == AOUT_OPENSLES ? AOUT_OPENSLES : AOUT_AUDIOTRACK;
+        return aout == AOUT_OPENSLES ? "opensles_android" : "android_audiotrack";
     }
 
     private static int getDeblocking(int deblocking) {



More information about the Android mailing list