[Android] simplify & fix settings which require a libvlc restart
Sébastien Toque
git at videolan.org
Sun Dec 16 10:11:14 CET 2012
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sun Dec 16 10:02:17 2012 +0100| [66e9110e8cd02bf0039a0cf149c6c6b2ddf5e482] | committer: Sébastien Toque
simplify & fix settings which require a libvlc restart
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=66e9110e8cd02bf0039a0cf149c6c6b2ddf5e482
---
vlc-android/src/org/videolan/vlc/LibVLC.java | 59 ++++++++------------
.../org/videolan/vlc/gui/PreferencesActivity.java | 47 ++++++----------
2 files changed, 39 insertions(+), 67 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 4d380b3..f836200 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -38,8 +38,6 @@ public class LibVLC {
private static final int AOUT_OPENSLES = 2;
private static LibVLC sInstance;
- private static boolean sUseIomx = false;
- private static int sAout = AOUT_AUDIOTRACK_JAVA;
/** libVLC instance C pointer */
private long mLibVlcInstance = 0; // Read-only, reserved for JNI
@@ -56,7 +54,6 @@ public class LibVLC {
/** Check in libVLC already initialized otherwise crash */
private boolean mIsInitialized = false;
-
public native void attachSurface(Surface surface, VideoPlayerActivity player, int width, int height);
public native void detachSurface();
@@ -144,35 +141,7 @@ public class LibVLC {
*/
public native void setSurface(Surface f);
- /**
- *
- */
- public boolean useIOMX() {
- return sUseIomx;
- }
-
- public static synchronized void setIOMX(boolean enable) {
- sUseIomx = enable;
- }
-
- public int getAout() {
- return sAout;
- }
-
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_OPENSLES)));
- } catch (NumberFormatException nfe) {
- sAout = AOUT_OPENSLES;
- }
-
- if (!Util.isGingerbreadOrLater() && sAout == AOUT_OPENSLES) {
- sAout = AOUT_AUDIOTRACK_JAVA;
- }
-
if (sInstance != null) {
try {
sInstance.destroy();
@@ -183,15 +152,33 @@ public class LibVLC {
}
}
- public boolean timeStretchingEnabled() {
- SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
- return p.getBoolean("enable_time_stretching_audio", false);
+ /**
+ * those are called from native code to get settings values
+ */
+ public boolean useIOMX() {
+ final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+ return p.getBoolean("enable_iomx", false);
}
-
public String getSubtitlesEncoding() {
- SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+ final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
return p.getString("subtitles_text_encoding", "");
}
+ public int getAout() {
+ final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+ int defaultAout = Util.isGingerbreadOrLater() ? AOUT_OPENSLES : AOUT_AUDIOTRACK_JAVA;
+ int aout = defaultAout;
+ try {
+ aout = Integer.parseInt(p.getString("aout", String.valueOf(defaultAout)));
+ }
+ catch (NumberFormatException nfe) {
+ aout = defaultAout;
+ }
+ return aout;
+ }
+ public boolean timeStretchingEnabled() {
+ final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+ return p.getBoolean("enable_time_stretching_audio", false);
+ }
/**
* Initialize the libVLC class
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 772c808..fbe017e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -33,6 +33,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@@ -46,7 +47,7 @@ import android.util.Log;
import android.widget.Toast;
@SuppressWarnings("deprecation")
-public class PreferencesActivity extends PreferenceActivity {
+public class PreferencesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
public final static String TAG = "VLC/PreferencesActivity";
@@ -98,18 +99,6 @@ public class PreferencesActivity extends PreferenceActivity {
}
});
- // HW decoding
- CheckBoxPreference checkboxHW = (CheckBoxPreference) findPreference("enable_iomx");
- checkboxHW.setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- CheckBoxPreference checkboxHW = (CheckBoxPreference) preference;
- LibVLC.setIOMX(checkboxHW.isChecked());
- return true;
- }
- });
-
// Headset detection option
CheckBoxPreference checkboxHS = (CheckBoxPreference) findPreference("enable_headset_detection");
checkboxHS.setOnPreferenceClickListener(
@@ -175,24 +164,6 @@ public class PreferencesActivity extends PreferenceActivity {
aoutPref.setDefaultValue(2/*AOUT_OPENSLES*/);
else
aoutPref.setDefaultValue(0/*AOUT_AUDIOTRACK_JAVA*/);
- aoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- 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;
- }
- });
// Attach debugging items
Preference quitAppPref = findPreference("quit_app");
@@ -225,6 +196,20 @@ public class PreferencesActivity extends PreferenceActivity {
return true;
}
});
+
+ // SharedPreferences Listener to apply changes
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+ sharedPrefs.registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (key.equalsIgnoreCase("enable_iomx") ||
+ key.equalsIgnoreCase("subtitles_text_encoding") ||
+ key.equalsIgnoreCase("aout") ||
+ key.equalsIgnoreCase("enable_time_stretching_audio")) {
+ LibVLC.startPrefs(this);
+ }
}
@Override
More information about the Android
mailing list