[Android] subtitle track selection

Sébastien Toque git at videolan.org
Tue May 29 20:41:12 CEST 2012


android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sat May 26 14:12:03 2012 +0200| [c7dbd8bb3dcedfa4fbdcf3dcaebf2194ab567c93] | committer: Sébastien Toque

subtitle track selection

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

 vlc-android/jni/libvlcjni.c                        |   39 ++++++++++++++++++++
 vlc-android/res/drawable/header_icon_subtitle.png  |  Bin 0 -> 1116 bytes
 vlc-android/res/layout/player.xml                  |    8 ++++
 vlc-android/src/org/videolan/vlc/LibVLC.java       |    6 +++
 .../vlc/gui/video/VideoPlayerActivity.java         |   36 ++++++++++++++++++
 5 files changed, 89 insertions(+)

diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index fdce905..7cefc52 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -870,6 +870,30 @@ jint Java_org_videolan_vlc_LibVLC_getVideoTracksCount(JNIEnv *env, jobject thiz)
     return -1;
 }
 
+jobjectArray Java_org_videolan_vlc_LibVLC_getSpuTrackDescription(JNIEnv *env, jobject thiz)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (!mp)
+        return NULL;
+
+    int i_nbTracks = libvlc_video_get_spu_count(mp);
+    jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks,
+            (*env)->FindClass(env, "java/lang/String"),
+            NULL);
+
+    libvlc_track_description_t *first = libvlc_video_get_spu_description(mp);
+    libvlc_track_description_t *desc = first;
+    unsigned i;
+    for (i = 0; i < i_nbTracks; ++i)
+    {
+        jstring name = (*env)->NewStringUTF(env, desc->psz_name);
+        (*env)->SetObjectArrayElement(env, array, i, name);
+        desc = desc->p_next;
+    }
+    libvlc_track_description_list_release(first);
+    return array;
+}
+
 jint Java_org_videolan_vlc_LibVLC_getSpuTracksCount(JNIEnv *env, jobject thiz)
 {
     libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
@@ -878,3 +902,18 @@ jint Java_org_videolan_vlc_LibVLC_getSpuTracksCount(JNIEnv *env, jobject thiz)
     return -1;
 }
 
+jint Java_org_videolan_vlc_LibVLC_getSpuTrack(JNIEnv *env, jobject thiz)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (mp)
+        return libvlc_video_get_spu(mp);
+    return -1;
+}
+
+jint Java_org_videolan_vlc_LibVLC_setSpuTrack(JNIEnv *env, jobject thiz, jint index)
+{
+    libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
+    if (mp)
+        return libvlc_video_set_spu(mp, index);
+    return -1;
+}
diff --git a/vlc-android/res/drawable/header_icon_subtitle.png b/vlc-android/res/drawable/header_icon_subtitle.png
new file mode 100644
index 0000000..dfe8609
Binary files /dev/null and b/vlc-android/res/drawable/header_icon_subtitle.png differ
diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index cc87262..4f7cdfb 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -49,6 +49,14 @@
             android:layout_marginRight="10dp"
             android:background="@drawable/header_icon_audio" />
 
+        <ImageButton
+            android:id="@+id/player_overlay_subtitle"
+            android:layout_width="40dp"
+            android:layout_height="40dp"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="10dp"
+            android:background="@drawable/header_icon_subtitle" />
+
         <LinearLayout
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index aaefc00..baa28ea 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -389,6 +389,12 @@ public class LibVLC {
 
     public native int getVideoTracksCount();
 
+    public native String[] getSpuTrackDescription();
+
+    public native int getSpuTrack();
+
+    public native int setSpuTrack(int index);
+
     public native int getSpuTracksCount();
 
     public native String nativeToURI(String path);
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 023d090..d214abb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -110,6 +110,7 @@ public class VideoPlayerActivity extends Activity {
     private TextView mInfo;
     private IPlayerControl mControls;
     private ImageButton mAudio;
+    private ImageButton mSubtitles;
     private ImageButton mLock;
     private ImageButton mSize;
 
@@ -127,6 +128,7 @@ public class VideoPlayerActivity extends Activity {
     private float mTouchY, mVol;
     private boolean mIsAudioChanged;
     private String[] mAudioTracks;
+    private String[] mSubtitleTracks;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -163,6 +165,9 @@ public class VideoPlayerActivity extends Activity {
         mAudio = (ImageButton) findViewById(R.id.player_overlay_audio);
         mAudio.setOnClickListener(mAudioListener);
 
+        mSubtitles = (ImageButton) findViewById(R.id.player_overlay_subtitle);
+        mSubtitles.setOnClickListener(mSubtitlesListener);
+
         mLock = (ImageButton) findViewById(R.id.player_overlay_lock);
         mLock.setOnClickListener(mLockListener);
 
@@ -563,6 +568,30 @@ public class VideoPlayerActivity extends Activity {
     /**
     *
     */
+   private OnClickListener mSubtitlesListener = new OnClickListener() {
+       public void onClick(View v) {
+           if (mSubtitleTracks == null || mSubtitleTracks.length == 0)
+               return;
+
+           int current = mLibVLC.getSpuTrack();
+
+           Builder builder = new AlertDialog.Builder(VideoPlayerActivity.this);
+           builder.setSingleChoiceItems(mSubtitleTracks, current, new DialogInterface.OnClickListener() {
+               @Override
+               public void onClick(DialogInterface dialog, int which) {
+                   dialog.dismiss();
+                   mLibVLC.setSpuTrack(which);
+               }
+           });
+
+           builder.show();
+       }
+   };
+
+
+    /**
+    *
+    */
     private OnPlayerControlListener mPlayerControlListener = new OnPlayerControlListener() {
         @Override
         public void onPlayPause() {
@@ -707,6 +736,13 @@ public class VideoPlayerActivity extends Activity {
             else
                 mAudio.setVisibility(View.GONE);
         }
+        if (mSubtitleTracks == null) {
+            mSubtitleTracks = mLibVLC.getSpuTrackDescription();
+            if (mSubtitleTracks != null && mSubtitleTracks.length > 0)
+                mSubtitles.setVisibility(View.VISIBLE);
+            else
+                mSubtitles.setVisibility(View.GONE);
+        }
         updateOverlayPausePlay();
     }
 



More information about the Android mailing list