[Android] MediaList: add loadPlaylist()
Edward Wang
git at videolan.org
Wed Aug 28 17:23:20 CEST 2013
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Wed Aug 28 13:11:21 2013 +0200| [f3c4629749daf10496893ab100495bf13da0c141] | committer: Edward Wang
MediaList: add loadPlaylist()
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=f3c4629749daf10496893ab100495bf13da0c141
---
vlc-android/jni/libvlcjni-medialist.c | 60 ++++++++++++++++++++
vlc-android/src/org/videolan/libvlc/MediaList.java | 5 ++
2 files changed, 65 insertions(+)
diff --git a/vlc-android/jni/libvlcjni-medialist.c b/vlc-android/jni/libvlcjni-medialist.c
index a516c71..cf2d084 100644
--- a/vlc-android/jni/libvlcjni-medialist.c
+++ b/vlc-android/jni/libvlcjni-medialist.c
@@ -22,6 +22,7 @@
#include <vlc/vlc.h>
#include <vlc/libvlc_media_list.h>
#include <stdlib.h>
+#include <pthread.h>
#include "utils.h"
#define LOG_TAG "VLC/JNI/MediaList"
@@ -30,6 +31,21 @@
/** Unique Java VM instance, as defined in libvlcjni.c */
extern JavaVM *myVm;
+struct stopped_monitor {
+ pthread_mutex_t doneMutex;
+ pthread_cond_t doneCondVar;
+ bool stopped;
+};
+
+static void stopped_callback(const libvlc_event_t *ev, void *data)
+{
+ struct stopped_monitor* monitor = data;
+ pthread_mutex_lock(&monitor->doneMutex);
+ monitor->stopped = true;
+ pthread_cond_signal(&monitor->doneCondVar);
+ pthread_mutex_unlock(&monitor->doneMutex);
+}
+
// data is the MediaList Java object of the media list
static void vlc_media_list_event_callback(const libvlc_event_t *ev, void *data)
{
@@ -173,6 +189,50 @@ jint Java_org_videolan_libvlc_MediaList_expandMedia(JNIEnv *env, jobject thiz, j
return ret;
}
+void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz, jobject libvlcJava, jstring mrl) {
+ libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
+ const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL);
+
+ libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), p_mrl);
+ libvlc_media_add_option(p_md, ":demux=playlist,none");
+ libvlc_media_add_option(p_md, ":run-time=1");
+
+ struct stopped_monitor* monitor = malloc(sizeof(struct stopped_monitor));
+ pthread_mutex_init(&monitor->doneMutex, NULL);
+ pthread_cond_init(&monitor->doneCondVar, NULL);
+ monitor->stopped = false;
+ pthread_mutex_lock(&monitor->doneMutex);
+
+ libvlc_media_player_t* p_mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"));
+ libvlc_event_manager_t* ev = libvlc_media_player_event_manager(p_mp);
+ libvlc_event_attach(ev, libvlc_MediaPlayerEndReached, stopped_callback, monitor);
+ libvlc_media_player_set_media(p_mp, p_md);
+ libvlc_media_player_play(p_mp);
+
+ struct timespec deadline;
+ clock_gettime(CLOCK_REALTIME, &deadline);
+ deadline.tv_sec += 2; /* If "VLC can't open the file", return */
+ int mp_alive = 1;
+ while(!(monitor->stopped) && mp_alive) {
+ pthread_cond_timedwait(&monitor->doneCondVar, &monitor->doneMutex, &deadline);
+ mp_alive = libvlc_media_player_will_play(p_mp);
+ }
+ pthread_mutex_unlock(&monitor->doneMutex);
+ pthread_mutex_destroy(&monitor->doneMutex);
+ pthread_cond_destroy(&monitor->doneCondVar);
+ free(monitor);
+
+ libvlc_media_player_release(p_mp);
+
+ libvlc_media_list_lock(p_ml);
+ int pos = libvlc_media_list_count(p_ml);
+ libvlc_media_list_add_media(p_ml, p_md);
+ expand_media_internal(p_ml, pos);
+ libvlc_media_list_unlock(p_ml);
+
+ (*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
+}
+
void Java_org_videolan_libvlc_MediaList_remove(JNIEnv *env, jobject thiz, jint position) {
libvlc_media_list_t* p_ml = getMediaListFromJava(env, thiz);
libvlc_media_list_lock(p_ml);
diff --git a/vlc-android/src/org/videolan/libvlc/MediaList.java b/vlc-android/src/org/videolan/libvlc/MediaList.java
index a994dd8..2405e2d 100644
--- a/vlc-android/src/org/videolan/libvlc/MediaList.java
+++ b/vlc-android/src/org/videolan/libvlc/MediaList.java
@@ -73,6 +73,11 @@ public class MediaList {
*/
public native int expandMedia(int position);
+ public void loadPlaylist(String mrl) {
+ loadPlaylist(mLibVLC, mrl);
+ }
+ private native void loadPlaylist(LibVLC libvlc_instance, String mrl);
+
public void insert(int position, String mrl) {
insert(mLibVLC, position, mrl);
}
More information about the Android
mailing list