Commit c7dbd8bb authored by Sébastien Toque's avatar Sébastien Toque
Browse files

subtitle track selection

parent 84a3b055
......@@ -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;
}
......@@ -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"
......
......@@ -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);
......
......@@ -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);
......@@ -560,6 +565,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();
}
};
/**
*
*/
......@@ -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();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment