Commit 24d71df7 authored by Edward Wang's avatar Edward Wang Committed by Sébastien Toque
Browse files

jni: control playback with media_player and remove media_list_player



Ref #8895
Signed-off-by: Sébastien Toque's avatarSébastien Toque <xilasz@gmail.com>
parent 4161cd02
...@@ -180,22 +180,14 @@ static libvlc_media_player_t *getMediaPlayer(JNIEnv *env, jobject thiz) ...@@ -180,22 +180,14 @@ static libvlc_media_player_t *getMediaPlayer(JNIEnv *env, jobject thiz)
return (libvlc_media_player_t*)(intptr_t)getLong(env, thiz, "mInternalMediaPlayerInstance"); return (libvlc_media_player_t*)(intptr_t)getLong(env, thiz, "mInternalMediaPlayerInstance");
} }
static libvlc_media_list_player_t *getMediaListPlayer(JNIEnv *env, jobject thiz)
{
return (libvlc_media_list_player_t*)(intptr_t)getLong(env, thiz, "mMediaListPlayerInstance");
}
static void releaseMediaPlayer(JNIEnv *env, jobject thiz) static void releaseMediaPlayer(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t* p_mlp = getMediaListPlayer(env, thiz); libvlc_media_player_t* p_mp = getMediaPlayer(env, thiz);
if (p_mlp) if (p_mp)
{ {
libvlc_media_list_player_stop(p_mlp); libvlc_media_player_stop(p_mp);
libvlc_media_list_player_release(p_mlp); libvlc_media_player_release(p_mp);
/* libvlc_media_list_player_release frees the media player, so
* we don't free it ourselves. */
setLong(env, thiz, "mInternalMediaPlayerInstance", 0); setLong(env, thiz, "mInternalMediaPlayerInstance", 0);
setLong(env, thiz, "mMediaListPlayerInstance", 0);
} }
} }
...@@ -677,7 +669,6 @@ static void create_player_and_play(JNIEnv* env, jobject thiz, ...@@ -677,7 +669,6 @@ static void create_player_and_play(JNIEnv* env, jobject thiz,
libvlc_media_list_t* p_mlist = getMediaList(env, thiz); libvlc_media_list_t* p_mlist = getMediaList(env, thiz);
/* Create a media player playing environment */ /* Create a media player playing environment */
libvlc_media_list_player_t* p_mlp = libvlc_media_list_player_new((libvlc_instance_t*)(intptr_t)instance);
libvlc_media_player_t *mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)instance); libvlc_media_player_t *mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)instance);
jobject myJavaLibVLC = (*env)->NewGlobalRef(env, thiz); jobject myJavaLibVLC = (*env)->NewGlobalRef(env, thiz);
...@@ -706,14 +697,16 @@ static void create_player_and_play(JNIEnv* env, jobject thiz, ...@@ -706,14 +697,16 @@ static void create_player_and_play(JNIEnv* env, jobject thiz,
for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++) for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm); libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm);
libvlc_media_list_player_set_media_list(p_mlp, p_mlist);
libvlc_media_list_player_set_media_player(p_mlp, mp);
/* Keep a pointer to this media player */ /* Keep a pointer to this media player */
setLong(env, thiz, "mMediaListPlayerInstance", (jlong)(intptr_t)p_mlp);
setLong(env, thiz, "mInternalMediaPlayerInstance", (jlong)(intptr_t)mp); setLong(env, thiz, "mInternalMediaPlayerInstance", (jlong)(intptr_t)mp);
libvlc_media_list_player_play_item_at_index(p_mlp, position); setInt(env, thiz, "mInternalMediaPlayerIndex", (jint)position);
libvlc_media_list_lock(p_mlist);
libvlc_media_t* p_md = libvlc_media_list_item_at_index(p_mlist, position);
libvlc_media_list_unlock(p_mlist);
libvlc_media_player_set_media(mp, p_md);
libvlc_media_player_play(mp);
} }
jint Java_org_videolan_libvlc_LibVLC_readMedia(JNIEnv *env, jobject thiz, jint Java_org_videolan_libvlc_LibVLC_readMedia(JNIEnv *env, jobject thiz,
...@@ -1002,14 +995,14 @@ end: ...@@ -1002,14 +995,14 @@ end:
jboolean Java_org_videolan_libvlc_LibVLC_hasMediaPlayer(JNIEnv *env, jobject thiz) jboolean Java_org_videolan_libvlc_LibVLC_hasMediaPlayer(JNIEnv *env, jobject thiz)
{ {
return !!getMediaListPlayer(env, thiz); return !!getMediaPlayer(env, thiz);
} }
jboolean Java_org_videolan_libvlc_LibVLC_isPlaying(JNIEnv *env, jobject thiz) jboolean Java_org_videolan_libvlc_LibVLC_isPlaying(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp) if (mp)
return !!libvlc_media_list_player_is_playing(mp); return !!libvlc_media_player_is_playing(mp);
else else
return 0; return 0;
} }
...@@ -1024,37 +1017,46 @@ jboolean Java_org_videolan_libvlc_LibVLC_isSeekable(JNIEnv *env, jobject thiz) ...@@ -1024,37 +1017,46 @@ jboolean Java_org_videolan_libvlc_LibVLC_isSeekable(JNIEnv *env, jobject thiz)
void Java_org_videolan_libvlc_LibVLC_play(JNIEnv *env, jobject thiz) void Java_org_videolan_libvlc_LibVLC_play(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp) if (mp)
libvlc_media_list_player_play(mp); libvlc_media_player_play(mp);
} }
void Java_org_videolan_libvlc_LibVLC_pause(JNIEnv *env, jobject thiz) void Java_org_videolan_libvlc_LibVLC_pause(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp) if (mp)
libvlc_media_list_player_pause(mp); libvlc_media_player_pause(mp);
} }
void Java_org_videolan_libvlc_LibVLC_stop(JNIEnv *env, jobject thiz) void Java_org_videolan_libvlc_LibVLC_stop(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp) if (mp)
libvlc_media_list_player_stop(mp); libvlc_media_player_stop(mp);
} }
void Java_org_videolan_libvlc_LibVLC_previous(JNIEnv *env, jobject thiz) void Java_org_videolan_libvlc_LibVLC_previous(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); int current_position = getInt(env, thiz, "mInternalMediaPlayerIndex");
if (mp)
libvlc_media_list_player_previous(mp); if(current_position-1 >= 0) {
setInt(env, thiz, "mInternalMediaPlayerIndex", (jint)(current_position-1));
create_player_and_play(env, thiz,
getLong(env, thiz, "mLibVlcInstance"), current_position-1);
}
} }
void Java_org_videolan_libvlc_LibVLC_next(JNIEnv *env, jobject thiz) void Java_org_videolan_libvlc_LibVLC_next(JNIEnv *env, jobject thiz)
{ {
libvlc_media_list_player_t *mp = getMediaListPlayer(env, thiz); libvlc_media_list_t* p_mlist = getMediaList(env, thiz);
if (mp) int current_position = getInt(env, thiz, "mInternalMediaPlayerIndex");
libvlc_media_list_player_next(mp);
if(current_position+1 < libvlc_media_list_count(p_mlist)) {
setInt(env, thiz, "mInternalMediaPlayerIndex", (jint)(current_position+1));
create_player_and_play(env, thiz,
getLong(env, thiz, "mLibVlcInstance"), current_position+1);
}
} }
jint Java_org_videolan_libvlc_LibVLC_getVolume(JNIEnv *env, jobject thiz) jint Java_org_videolan_libvlc_LibVLC_getVolume(JNIEnv *env, jobject thiz)
......
...@@ -38,8 +38,8 @@ public class LibVLC { ...@@ -38,8 +38,8 @@ public class LibVLC {
/** libVLC instance C pointer */ /** libVLC instance C pointer */
private long mLibVlcInstance = 0; // Read-only, reserved for JNI private long mLibVlcInstance = 0; // Read-only, reserved for JNI
/** libvlc_media_list_player pointer */ /** libvlc_media_player pointer and index */
private long mMediaListPlayerInstance = 0; // Read-only, reserved for JNI private int mInternalMediaPlayerIndex = 0; // Read-only, reserved for JNI
private long mInternalMediaPlayerInstance = 0; // Read-only, reserved for JNI private long mInternalMediaPlayerInstance = 0; // Read-only, reserved for JNI
/** libvlc_media_list_t pointer */ /** libvlc_media_list_t pointer */
private long mMediaListInstance = 0; // Read-only, reserved for JNI private long mMediaListInstance = 0; // Read-only, reserved for JNI
......
Markdown is supported
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