[Android] Store the AOUT preference as an Integer and not a string

Jean-Baptiste Kempf git at videolan.org
Mon Oct 8 15:25:17 CEST 2012


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Oct  8 15:19:18 2012 +0200| [94ed689e0e60847b0a9c94cff133e608163dc0b5] | committer: Jean-Baptiste Kempf

Store the AOUT preference as an Integer and not a string

This solve a crash and an issue when changing language or updating the
strings between versions...

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

 vlc-android/res/values/strings.xml                    |   12 +++++++++++-
 vlc-android/src/org/videolan/vlc/LibVLC.java          |   17 ++++++++---------
 .../src/org/videolan/vlc/gui/PreferencesActivity.java |    5 +++--
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 1110475..6cf1773 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -168,4 +168,14 @@
         <item>@string/aout_audiotrack</item>
         <item>@string/aout_opensles</item>
     </string-array>
-</resources>
+    <string-array name="aouts_values_froyo">
+        <item>0</item>
+        <item>1</item>
+    </string-array>
+    <string-array name="aouts_values">
+        <item>0</item>
+        <item>1</item>
+        <item>2</item>
+    </string-array>
+
+</resources>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index ec2fc38..b29455f 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -26,7 +26,6 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity;
 
 import android.content.Context;
 import android.content.SharedPreferences;
-import android.content.res.Resources;
 import android.os.Build;
 import android.preference.PreferenceManager;
 import android.util.Log;
@@ -34,13 +33,13 @@ import android.view.Surface;
 
 public class LibVLC {
     private static final String TAG = "VLC/LibVLC";
-    private static final int AOUT_AUDIOTRACK = 0;
-    private static final int AOUT_AUDIOTRACK_JAVA = 1;
+    private static final int AOUT_AUDIOTRACK = 1;
+    private static final int AOUT_AUDIOTRACK_JAVA = 0;
     private static final int AOUT_OPENSLES = 2;
 
     private static LibVLC sInstance;
     private static boolean sUseIomx = false;
-    private static int sAout = AOUT_AUDIOTRACK;
+    private static int sAout = AOUT_AUDIOTRACK_JAVA;
 
     /** libVLC instance C pointer */
     private long mLibVlcInstance = 0; // Read-only, reserved for JNI
@@ -157,14 +156,14 @@ public class LibVLC {
     public static synchronized void useIOMX(Context context) {
         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
         sUseIomx = pref.getBoolean("enable_iomx", false);
-        setAout(context, pref.getString("aout", "error"), false);
+        sAout = pref.getInt("aout", AOUT_AUDIOTRACK_JAVA);
     }
 
-    public static synchronized void setAout(Context context, String aoutPref, boolean reset) {
-        Resources res = context.getResources();
-        if (aoutPref.equals(res.getString(R.string.aout_audiotrack)))
+    public static synchronized void setAout(Context context, Integer aoutPref,
+            boolean reset) {
+        if (aoutPref == AOUT_AUDIOTRACK)
             sAout = AOUT_AUDIOTRACK;
-        else if (aoutPref.equals(res.getString(R.string.aout_opensles)) && Util.isGingerbreadOrLater())
+        else if (aoutPref == AOUT_OPENSLES && Util.isGingerbreadOrLater())
             sAout = AOUT_OPENSLES;
         else
             sAout = AOUT_AUDIOTRACK_JAVA;
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 329839b..28fbe01 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -151,12 +151,13 @@ public class PreferencesActivity extends PreferenceActivity {
         // Audio output
         ListPreference aoutPref = (ListPreference) findPreference("aout");
         int aoutEntriesId = Util.isGingerbreadOrLater() ? R.array.aouts : R.array.aouts_froyo;
+        int aoutEntriesIdValues = Util.isGingerbreadOrLater() ? R.array.aouts_values : R.array.aouts_values_froyo;
         aoutPref.setEntries(aoutEntriesId);
-        aoutPref.setEntryValues(aoutEntriesId);
+        aoutPref.setEntryValues(aoutEntriesIdValues);
         aoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
             @Override
             public boolean onPreferenceChange(Preference preference, Object newValue) {
-                LibVLC.setAout(PreferencesActivity.this, (String) newValue, true);
+                LibVLC.setAout(PreferencesActivity.this, (Integer) newValue, true);
                 return true;
             }
         });



More information about the Android mailing list