[Android] Mediaplayer: split of playMRL and create
Jean-Baptiste Kempf
git at videolan.org
Mon May 25 16:13:20 CEST 2015
vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon May 25 15:55:41 2015 +0200| [42da1c79e3052828807fd9c69191f517de2a5313] | committer: Jean-Baptiste Kempf
Mediaplayer: split of playMRL and create
This should avoid destroying and recreating the MediaPlayer on each play
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=42da1c79e3052828807fd9c69191f517de2a5313
---
libvlc/jni/libvlcjni-mediaplayer.c | 19 ++++++++++++++-----
libvlc/src/org/videolan/libvlc/MediaPlayer.java | 3 +++
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/libvlc/jni/libvlcjni-mediaplayer.c b/libvlc/jni/libvlcjni-mediaplayer.c
index 33a668f..6e5d318 100644
--- a/libvlc/jni/libvlcjni-mediaplayer.c
+++ b/libvlc/jni/libvlcjni-mediaplayer.c
@@ -156,10 +156,8 @@ end:
(*env)->DeleteLocalRef(env, bundle);
}
-void Java_org_videolan_libvlc_MediaPlayer_playMRL(JNIEnv *env, jobject thiz,
- jstring mrl, jobjectArray mediaOptions)
+void Java_org_videolan_libvlc_MediaPlayer_create(JNIEnv *env, jobject thiz)
{
- jclass cls;
/* Release previous media player, if any */
releaseMediaPlayer(env, thiz);
@@ -189,14 +187,24 @@ void Java_org_videolan_libvlc_MediaPlayer_playMRL(JNIEnv *env, jobject thiz,
/* Keep a pointer to this media player */
setLong(env, thiz, "mInternalMediaPlayerInstance", (jlong)(intptr_t)mp);
+}
+
+void Java_org_videolan_libvlc_MediaPlayer_playMRL(JNIEnv *env, jobject thiz,
+ jstring mrl, jobjectArray mediaOptions)
+{
+ /* libVLC instance */
+ libvlc_instance_t *p_instance = getLibVlcInstance(env, thiz);
+ libvlc_media_player_t* mp = getMediaPlayer(env, thiz);
- cls = (*env)->GetObjectClass(env, thiz);
+ /* Equalizer */
+ jclass cls = (*env)->GetObjectClass(env, thiz);
jmethodID methodID = (*env)->GetMethodID(env, cls, "applyEqualizer", "()V");
(*env)->CallVoidMethod(env, thiz, methodID);
+ /* New Media */
const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);
-
libvlc_media_t* p_md = libvlc_media_new_location(p_instance, p_mrl);
+
/* media options */
if (mediaOptions != NULL)
add_media_options(p_md, env, mediaOptions);
@@ -213,6 +221,7 @@ void Java_org_videolan_libvlc_MediaPlayer_playMRL(JNIEnv *env, jobject thiz,
libvlc_event_attach(ev_media, mp_media_events[i], vlc_event_callback, NULL);
libvlc_media_player_set_media(mp, p_md);
+
libvlc_media_player_play(mp);
}
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 9d3f623..9de2add 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -31,8 +31,11 @@ public class MediaPlayer {
private LibVLC mLibVLC;
public MediaPlayer(LibVLC libVLC) {
mLibVLC = libVLC;
+ create();
}
+ private native void create();
+
// REMOVE ASAP
public LibVLC getLibVLC() {
return mLibVLC;
More information about the Android
mailing list