[Android] Mediaplayer: split of playMRL and create
Jean-Baptiste Kempf
git at videolan.org
Wed May 27 12:37:56 CEST 2015
vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Tue May 26 13:52:47 2015 +0200| [ecc62cc9702eac53fc142c73a39bf5b3f16632e6] | committer: Thomas Guillem
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=ecc62cc9702eac53fc142c73a39bf5b3f16632e6
---
libvlc/jni/libvlcjni-mediaplayer.c | 19 ++++++++++++++-----
libvlc/src/org/videolan/libvlc/MediaPlayer.java | 3 +++
.../videolan/vlc/gui/video/VideoPlayerActivity.java | 2 +-
3 files changed, 18 insertions(+), 6 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;
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 e9ad7a7..05ab6dc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -342,7 +342,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
}
mLibVLC = VLCInstance.get();
- mMediaPlayer = new MediaPlayer(mLibVLC);
+ mMediaPlayer = VLCInstance.getMainMediaPlayer();
if (LibVlcUtil.isJellyBeanMR1OrLater()) {
// Get the media router service (Miracast)
More information about the Android
mailing list