[Android] Audio service: add a function to move a media inside the playlist

Adrien Maglo git at videolan.org
Thu Jan 23 18:41:46 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Thu Jan 23 18:41:07 2014 +0100| [fe7db8c83ca13ebac37e71787ee8f2c288fdd317] | committer: Adrien Maglo

Audio service: add a function to move a media inside the playlist

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=fe7db8c83ca13ebac37e71787ee8f2c288fdd317
---

 vlc-android/src/org/videolan/libvlc/MediaList.java |    9 +++++++++
 vlc-android/src/org/videolan/vlc/AudioService.java |   21 ++++++++++++++++++++
 .../org/videolan/vlc/AudioServiceController.java   |    6 ++++++
 .../org/videolan/vlc/interfaces/IAudioService.aidl |    1 +
 4 files changed, 37 insertions(+)

diff --git a/vlc-android/src/org/videolan/libvlc/MediaList.java b/vlc-android/src/org/videolan/libvlc/MediaList.java
index b941522..deef78b 100644
--- a/vlc-android/src/org/videolan/libvlc/MediaList.java
+++ b/vlc-android/src/org/videolan/libvlc/MediaList.java
@@ -135,6 +135,15 @@ public class MediaList {
         signal_list_event(EventHandler.CustomMediaListItemAdded, position, media.getLocation());
     }
 
+    public void move(int startPosition, int endPosition) {
+        MediaHolder toMove = mInternalList.get(startPosition);
+        mInternalList.remove(startPosition);
+        if (startPosition >= endPosition)
+            mInternalList.add(endPosition, toMove);
+        else
+            mInternalList.add(endPosition - 1, toMove);
+    }
+
     public void remove(int position) {
         if (!isValid(position))
             return;
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index a1afe2b..a036d1c 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -1170,6 +1170,27 @@ public class AudioService extends Service {
             executeUpdate();
         }
 
+        /**
+         * Move an item inside the playlist.
+         */
+        @Override
+        public void moveItem(int positionStart, int positionEnd) throws RemoteException {
+            mLibVLC.getMediaList().move(positionStart, positionEnd);
+            if (mCurrentIndex == positionStart) {
+                mCurrentIndex = positionEnd;
+                if (positionEnd > positionStart)
+                    mCurrentIndex--;
+            }
+
+            // If we are in random mode, we completely reset the stored previous track
+            // as their indices changed.
+            // TODO: better handling of item move in random mode?
+            mPrevious.clear();
+
+            determinePrevAndNextIndices();
+            executeUpdate();
+        }
+
         @Override
         public List<String> getMediaLocations() {
             ArrayList<String> medias = new ArrayList<String>();
diff --git a/vlc-android/src/org/videolan/vlc/AudioServiceController.java b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
index fd0349e..1e4b652 100644
--- a/vlc-android/src/org/videolan/vlc/AudioServiceController.java
+++ b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
@@ -249,6 +249,12 @@ public class AudioServiceController implements IAudioPlayerControl {
                 new Object[] { mediaPathList } );
     }
 
+    public void moveItem(int positionStart, int positionEnd) {
+        remoteProcedureCall(mAudioServiceBinder, Void.class, (Void)null, "moveItem",
+                new Class<?>[] { int.class, int.class },
+                new Object[] { positionStart, positionEnd } );
+    }
+
     @SuppressWarnings("unchecked")
     public List<String> getMediaLocations() {
         List<String> def = new ArrayList<String>();
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
index 5600048..a316c40 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
@@ -31,6 +31,7 @@ interface IAudioService {
     void setTime(long time);
     void load(in List<String> mediaPathList, int position, boolean noVideo);
     void append(in List<String> mediaPathList);
+    void moveItem(int positionStart, int positionEnd);
     List<String> getMediaLocations();
     String getCurrentMediaLocation();
     boolean isPlaying();



More information about the Android mailing list