[Android] [PATCH 2/2] jni: expand subitems
Edward Wang
edward.c.wang at compdigitec.com
Sun Jul 21 20:27:40 CEST 2013
---
vlc-android/jni/libvlcjni.c | 33 ++++++++++
vlc-android/src/org/videolan/libvlc/LibVLC.java | 11 +++-
vlc-android/src/org/videolan/vlc/AudioService.java | 77 ++++++++++++++--------
3 files changed, 94 insertions(+), 27 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index dfbfd76..d9a6036 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -709,6 +709,39 @@ static void create_player_and_play(JNIEnv* env, jobject thiz,
libvlc_media_player_play(mp);
}
+jboolean Java_org_videolan_libvlc_LibVLC_expandMedia(JNIEnv *env, jobject thiz)
+{
+ int current_position = getInt(env, thiz, "mInternalMediaPlayerIndex");
+ libvlc_media_list_t* p_mlist = getMediaList(env, thiz);
+ libvlc_media_list_lock(p_mlist);
+ libvlc_media_t* p_md = libvlc_media_list_item_at_index(p_mlist, current_position);
+ libvlc_media_list_unlock(p_mlist);
+ libvlc_media_list_t* p_subitems = libvlc_media_subitems(p_md);
+ libvlc_media_release(p_md);
+ if(p_subitems) {
+ // Expand any subitems if needed
+ int subitem_count = libvlc_media_list_count(p_subitems);
+ if(subitem_count > 0) {
+ LOGD("Found %d subitems, expanding", subitem_count);
+ libvlc_media_list_lock(p_mlist);
+ for(int i = subitem_count - 1; i >= 0; i--) {
+ libvlc_media_list_insert_media(p_mlist, libvlc_media_list_item_at_index(p_subitems, i), current_position+1);
+ }
+ libvlc_media_list_remove_index(p_mlist, current_position);
+ libvlc_media_list_unlock(p_mlist);
+ }
+ libvlc_media_list_release(p_subitems);
+ if(subitem_count > 0) {
+ create_player_and_play(env, thiz,
+ getLong(env, thiz, "mLibVlcInstance"), current_position);
+ return JNI_TRUE;
+ } else
+ return JNI_FALSE;
+ } else {
+ return JNI_FALSE;
+ }
+}
+
jint Java_org_videolan_libvlc_LibVLC_readMedia(JNIEnv *env, jobject thiz,
jlong instance, jstring mrl, jboolean novideo)
{
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index b47f9d4..837aad1 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* LibVLC.java
*****************************************************************************
- * Copyright © 2010-2012 VLC authors and VideoLAN
+ * Copyright © 2010-2013 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
@@ -572,6 +572,15 @@ public class LibVLC {
*/
public native void getMediaListItems(ArrayList<String> arl);
+ /**
+ * A function to flatten the playlist. This function checks the
+ * currently playing media. If there are any subitems, it will
+ * expand them and replace the current media.
+ *
+ * @return true if a media was expanded, false otherwise
+ */
+ public native boolean expandMedia();
+
/**
* Return the length of the stream, in milliseconds
*/
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 4ef38f9..3e0ca04 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* AudioService.java
*****************************************************************************
- * Copyright © 2011-2012 VLC authors and VideoLAN
+ * Copyright © 2011-2013 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -415,6 +415,7 @@ public class AudioService extends Service {
service.changeAudioFocus(true);
service.setRemoteControlClientPlaybackState(EventHandler.MediaPlayerPlaying);
+ service.showNotification();
if (!service.mWakeLock.isHeld())
service.mWakeLock.acquire();
break;
@@ -639,34 +640,58 @@ public class AudioService extends Service {
}
private void next() {
- int index = mMediaList.indexOf(mCurrentMedia);
- mPrevious.push(mCurrentMedia);
- if (mRepeating == RepeatType.Once && index < mMediaList.size())
- mCurrentMedia = mMediaList.get(index);
- else if (mShuffling && mPrevious.size() < mMediaList.size()) {
- while (mPrevious.contains(mCurrentMedia = mMediaList
- .get((int) (Math.random() * mMediaList.size()))))
- ;
- } else if (!mShuffling && index < mMediaList.size() - 1) {
- mCurrentMedia = mMediaList.get(index + 1);
+ // Try to expand any items present
+ if(mLibVLC.expandMedia()) {
+ Log.d(TAG, "Found subitems, updating media display");
+ ArrayList<String> mediaPathList = new ArrayList<String>();
+ mLibVLC.getMediaListItems(mediaPathList);
+ int pos = mMediaList.indexOf(mCurrentMedia);
+ mMediaList.clear();
+ mPrevious.clear();
+
+ for(int i = 0; i < mediaPathList.size(); i++)
+ mMediaList.add(new Media(mediaPathList.get(i), i));
+ mCurrentMedia = mMediaList.get(pos);
+ mLibVLCPlaylistActive = true;
+ final AudioService service = this;
+ mVlcEventHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ service.executeUpdate();
+ }
+ }, 1000);
} else {
- if (mRepeating == RepeatType.All && mMediaList.size() > 0)
- mCurrentMedia = mMediaList.get(0);
- else {
- stop();
- return;
+ // No subitems; play the next item.
+ int index = mMediaList.indexOf(mCurrentMedia);
+ mPrevious.push(mCurrentMedia);
+ if (mRepeating == RepeatType.Once && index < mMediaList.size())
+ mCurrentMedia = mMediaList.get(index);
+ else if (mShuffling && mPrevious.size() < mMediaList.size()) {
+ while (mPrevious.contains(mCurrentMedia = mMediaList
+ .get((int) (Math.random() * mMediaList.size()))))
+ ;
+ } else if (!mShuffling && index < mMediaList.size() - 1) {
+ mCurrentMedia = mMediaList.get(index + 1);
+ } else {
+ if (mRepeating == RepeatType.All && mMediaList.size() > 0)
+ mCurrentMedia = mMediaList.get(0);
+ else {
+ stop();
+ return;
+ }
+ }
+ if(mLibVLCPlaylistActive) {
+ if(mRepeating == RepeatType.None)
+ mLibVLC.next();
+ else if(mRepeating == RepeatType.Once)
+ mLibVLC.playIndex(index);
+ else
+ mLibVLC.playIndex(mMediaList.indexOf(mCurrentMedia));
+ } else {
+ mLibVLC.readMedia(mCurrentMedia.getLocation(), true);
}
}
- if(mLibVLCPlaylistActive) {
- if(mRepeating == RepeatType.None)
- mLibVLC.next();
- else if(mRepeating == RepeatType.Once)
- mLibVLC.playIndex(index);
- else
- mLibVLC.playIndex(mMediaList.indexOf(mCurrentMedia));
- } else {
- mLibVLC.readMedia(mCurrentMedia.getLocation(), true);
- }
+
mHandler.sendEmptyMessage(SHOW_PROGRESS);
setUpRemoteControlClient();
showNotification();
--
1.8.3.2
More information about the Android
mailing list