[Android] [PATCH] Add an option to change the encoding of the subtitles
Ludovic Fauvet
etix at videolan.org
Wed Dec 5 18:14:11 CET 2012
---
vlc-android/jni/libvlcjni.c | 9 +++
vlc-android/res/values/strings.xml | 91 ++++++++++++++++++++++
vlc-android/res/xml/preferences.xml | 9 +++
vlc-android/src/org/videolan/vlc/LibVLC.java | 21 +++++
.../org/videolan/vlc/gui/PreferencesActivity.java | 12 +++
5 files changed, 142 insertions(+)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index be4ef01..f24e5a4 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -412,6 +412,12 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean
methodId = (*env)->GetMethodID(env, cls, "timeStretchingEnabled", "()Z");
bool enable_time_stretch = (*env)->CallBooleanMethod(env, thiz, methodId);
+ methodId = (*env)->GetMethodID(env, cls, "getSubtitlesEncoding", "()Ljava/lang/String;");
+ jstring subsencoding = (*env)->CallObjectMethod(env, thiz, methodId);
+ const char *subsencodingstr = (*env)->GetStringUTFChars(env, subsencoding, 0);
+
+ LOGD("Subtitles encoding sets to: %s", subsencodingstr);
+
verbosity = verbose;
libvlc_log_subscribe(&debug_subscriber, debug_log, &verbosity);
@@ -425,6 +431,7 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean
"--no-drop-late-frames",
"--avcodec-fast",
"--avcodec-threads=0",
+ "--subsdec-encoding", subsencodingstr,
enable_time_stretch ? "--audio-time-stretch" : "--no-audio-time-stretch",
use_opensles ? "--aout=opensles" : "--aout=android_audiotrack",
};
@@ -432,6 +439,8 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean
setLong(env, thiz, "mLibVlcInstance", (jlong)(intptr_t) instance);
+ (*env)->ReleaseStringUTFChars(env, subsencoding, subsencodingstr);
+
if (!instance)
{
jclass exc = (*env)->FindClass(env, "org/videolan/vlc/LibVlcException");
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 920dc3d..585633e 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -176,6 +176,8 @@
<string name="aout_opensles">OpenSL ES</string>
<string name="enable_time_stretching_audio">Enable time-stretching audio</string>
<string name="enable_time_stretching_audio_detail">Speed up and slow down audio without changing the pitch (requires a fast device)</string>
+ <string name="subtitles_prefs_category">Subtitles</string>
+ <string name="subtitles_text_encoding">Text encoding</string>
<string-array name="screen_orientation_list">
<item>@string/screen_orientation_sensor</item>
@@ -194,6 +196,95 @@
<item>9</item> <!-- 9 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT -->
</string-array>
+ <string-array name="subtitles_encoding_list">
+ <item>Default (Windows-1252)</item>
+ <item>Universal (UTF-8)</item>
+ <item>Universal (UTF-16)</item>
+ <item>Universal (big endian UTF-16)</item>
+ <item>Universal (little endian UTF-16)</item>
+ <item>Universal, Chinese (GB18030)</item>
+ <item>Western European (Latin-9)</item>
+ <item>Western European (Windows-1252)</item>
+ <item>Western European (IBM 00850)</item>
+ <item>Eastern European (Latin-2)</item>
+ <item>Eastern European (Windows-1250)</item>
+ <item>Esperanto (Latin-3)</item>
+ <item>Nordic (Latin-6)</item>
+ <item>Cyrillic (Windows-1251)</item>
+ <item>Russian (KOI8-R)</item>
+ <item>Ukrainian (KOI8-U)</item>
+ <item>Arabic (ISO 8859-6)</item>
+ <item>Arabic (Windows-1256)</item>
+ <item>Greek (ISO 8859-7)</item>
+ <item>Greek (Windows-1253)</item>
+ <item>Hebrew (ISO 8859-8)</item>
+ <item>Hebrew (Windows-1255)</item>
+ <item>Turkish (ISO 8859-9)</item>
+ <item>Turkish (Windows-1254)</item>
+ <item>Thai (TIS 620-2533/ISO 8859-11)</item>
+ <item>Thai (Windows-874)</item>
+ <item>Baltic (Latin-7)</item>
+ <item>Baltic (Windows-1257)</item>
+ <item>Celtic (Latin-8)</item>
+ <item>South-Eastern European (Latin-10)</item>
+ <item>Simplified Chinese (ISO-2022-CN-EXT)</item>
+ <item>Simplified Chinese Unix (EUC-CN)</item>
+ <item>Japanese (7-bits JIS/ISO-2022-JP-2)</item>
+ <item>Japanese Unix (EUC-JP)</item>
+ <item>Japanese (Shift JIS)</item>
+ <item>Korean (EUC-KR/CP949)</item>
+ <item>Korean (ISO-2022-KR)</item>
+ <item>Traditional Chinese (Big5)</item>
+ <item>Traditional Chinese Unix (EUC-TW)</item>
+ <item>Hong-Kong Supplementary (HKSCS)</item>
+ <item>Vietnamese (VISCII)</item>
+ <item>Vietnamese (Windows-1258)</item>
+ </string-array>
+ <string-array name="subtitles_encoding_values" translatable="false">
+ <item></item>
+ <item>UTF-8</item>
+ <item>UTF-16</item>
+ <item>UTF-16BE</item>
+ <item>UTF-16LE</item>
+ <item>GB18030</item>
+ <item>ISO-8859-15</item>
+ <item>Windows-1252</item>
+ <item>IBM850</item>
+ <item>ISO-8859-2</item>
+ <item>Windows-1250</item>
+ <item>ISO-8859-3</item>
+ <item>ISO-8859-10</item>
+ <item>Windows-1251</item>
+ <item>KOI8-R</item>
+ <item>KOI8-U</item>
+ <item>ISO-8859-6</item>
+ <item>Windows-1256</item>
+ <item>ISO-8859-7</item>
+ <item>Windows-1253</item>
+ <item>ISO-8859-8</item>
+ <item>Windows-1255</item>
+ <item>ISO-8859-9</item>
+ <item>Windows-1254</item>
+ <item>ISO-8859-11</item>
+ <item>Windows-874</item>
+ <item>ISO-8859-13</item>
+ <item>Windows-1257</item>
+ <item>ISO-8859-14</item>
+ <item>ISO-8859-16</item>
+ <item>ISO-2022-CN-EXT</item>
+ <item>EUC-CN</item>
+ <item>ISO-2022-JP-2</item>
+ <item>EUC-JP</item>
+ <item>Shift_JIS</item>
+ <item>CP949</item>
+ <item>ISO-2022-KR</item>
+ <item>Big5</item>
+ <item>ISO-2022-TW</item>
+ <item>Big5-HKSCS</item>
+ <item>VISCII</item>
+ <item>Windows-1258</item>
+ </string-array>
+
<string-array name="aouts_froyo">
<item>@string/aout_audiotrack_java</item>
<item>@string/aout_audiotrack</item>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index ade9998..cf42736 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -47,6 +47,15 @@
android:title="@string/clear_history">
</PreferenceScreen>
</PreferenceCategory>
+ <PreferenceCategory android:title="@string/subtitles_prefs_category">
+ <ListPreference
+ android:entries="@array/subtitles_encoding_list"
+ android:entryValues="@array/subtitles_encoding_values"
+ android:key="subtitles_text_encoding"
+ android:title="@string/subtitles_text_encoding"
+ android:defaultValue=""
+ android:persistent="true" />
+ </PreferenceCategory>
<PreferenceCategory android:title="@string/advanced_prefs_category">
<ListPreference
android:defaultValue="@string/aout_audiotrack_java"
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 9a2d727..7293153 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -26,6 +26,7 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -193,6 +194,26 @@ public class LibVLC {
return p.getBoolean("enable_time_stretching_audio", false);
}
+ public String getSubtitlesEncoding() {
+ SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+ 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/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 012d051..9a8c7a7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -133,6 +133,18 @@ 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() {
--
1.8.0.1
More information about the Android
mailing list