[Android] Factorize libvlc settings code

Rafaël Carré git at videolan.org
Sun Dec 16 01:13:11 CET 2012


vlc-ports/android | branch: master | Rafaël Carré <funman at videolan.org> | Sun Dec 16 01:06:20 2012 +0100| [7a7112c0514287b0739d20e106f4df0dcad08601] | committer: Rafaël Carré

Factorize libvlc settings code

- Merge all the helpers (setAout, useIOMX and setSubtitlesEncoding)
- Do not pass new settings by value
- Do not read/write subtitles encoding pref, it will be read directly
from the prefs before libvlc_new() (why isn't it done the same for omx and aout?)
- resetting libvlc is not optional

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

 vlc-android/src/org/videolan/vlc/AudioService.java |    2 +-
 vlc-android/src/org/videolan/vlc/LibVLC.java       |   32 ++++----------------
 .../src/org/videolan/vlc/gui/MainActivity.java     |    2 +-
 .../org/videolan/vlc/gui/PreferencesActivity.java  |   25 ++++++++-------
 .../vlc/gui/video/VideoPlayerActivity.java         |    2 +-
 5 files changed, 21 insertions(+), 42 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index d0e313d..6563303 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -116,7 +116,7 @@ public class AudioService extends Service {
 
         // Get libVLC instance
         try {
-            LibVLC.useIOMX(this);
+            LibVLC.startPrefs(this);
             mLibVLC = LibVLC.getInstance();
         } catch (LibVlcException e) {
             e.printStackTrace();
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 7293153..b7083f4 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -34,8 +34,8 @@ import android.view.Surface;
 
 public class LibVLC {
     private static final String TAG = "VLC/LibVLC";
-    private static final int AOUT_AUDIOTRACK = 1;
     private static final int AOUT_AUDIOTRACK_JAVA = 0;
+    private static final int AOUT_AUDIOTRACK = 1;
     private static final int AOUT_OPENSLES = 2;
 
     private static LibVLC sInstance;
@@ -160,26 +160,21 @@ public class LibVLC {
         return sAout;
     }
 
-    public static synchronized void useIOMX(Context context) {
+    public static synchronized void startPrefs(Context context) {
         SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
         sUseIomx = pref.getBoolean("enable_iomx", false);
+
         try {
             sAout = Integer.parseInt(pref.getString("aout", String.valueOf(AOUT_AUDIOTRACK_JAVA)));
         } catch (NumberFormatException nfe) {
             sAout = AOUT_AUDIOTRACK_JAVA;
         }
-    }
 
-    public static synchronized void setAout(Context context, Integer aoutPref,
-            boolean reset) {
-        if (aoutPref == AOUT_AUDIOTRACK)
-            sAout = AOUT_AUDIOTRACK;
-        else if (aoutPref == AOUT_OPENSLES && Util.isGingerbreadOrLater())
-            sAout = AOUT_OPENSLES;
-        else
+        if (!Util.isGingerbreadOrLater() && sAout == AOUT_OPENSLES) {
             sAout = AOUT_AUDIOTRACK_JAVA;
+        }
 
-        if (reset && sInstance != null) {
+        if (sInstance != null) {
             try {
                 sInstance.destroy();
                 sInstance.init();
@@ -199,21 +194,6 @@ public class LibVLC {
         return p.getString("subtitles_text_encoding", "");
     }
 
-    public static synchronized void setSubtitlesEncoding(Context context, String encoding, boolean reset) {
-        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
-        Editor e = pref.edit();
-        e.putString("subtitles_text_encoding", encoding);
-        e.commit();
-        if (reset && sInstance != null) {
-            try {
-                sInstance.destroy();
-                sInstance.init();
-            } catch (LibVlcException lve) {
-                Log.e(TAG, "Unable to reinit libvlc: " + lve);
-            }
-        }
-    }
-
     /**
      * Initialize the libVLC class
      */
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index aa8c92f..617366c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -141,7 +141,7 @@ public class MainActivity extends SherlockFragmentActivity {
         }
 
         /* Start VLC prefs */
-        LibVLC.useIOMX(this);
+        LibVLC.startPrefs(this);
 
         try {
             // Start LibVLC
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 9a8c7a7..5172f6f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -133,18 +133,6 @@ public class PreferencesActivity extends PreferenceActivity {
                     }
                 });
 
-        // Subtitles encoding
-        Preference subtitlesEncoding = (ListPreference)findPreference("subtitles_text_encoding");
-        subtitlesEncoding.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
-
-            @Override
-            public boolean onPreferenceChange(Preference preference, Object newValue) {
-                String encoding = (String)newValue;
-                LibVLC.setSubtitlesEncoding(preference.getContext(), encoding, true);
-                return true;
-            }
-        });
-
         // Change verbosity (logcat)
         CheckBoxPreference checkboxVerbosity = (CheckBoxPreference) findPreference("enable_verbose_mode");
         checkboxVerbosity.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@@ -186,7 +174,18 @@ public class PreferencesActivity extends PreferenceActivity {
         aoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
             @Override
             public boolean onPreferenceChange(Preference preference, Object newValue) {
-                LibVLC.setAout(PreferencesActivity.this, Integer.valueOf((String) newValue), true);
+                LibVLC.startPrefs(preference.getContext());
+                return true;
+            }
+        });
+
+        // Subtitles encoding
+        Preference subtitlesEncoding = (ListPreference)findPreference("subtitles_text_encoding");
+        subtitlesEncoding.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                LibVLC.startPrefs(preference.getContext());
                 return true;
             }
         });
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 ad33960..36f4fb4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -269,7 +269,7 @@ public class VideoPlayerActivity extends Activity {
         registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
 
         try {
-            LibVLC.useIOMX(this);
+            LibVLC.startPrefs(this);
             mLibVLC = LibVLC.getInstance();
         } catch (LibVlcException e) {
             Log.d(TAG, "LibVLC initialisation failed");



More information about the Android mailing list