[Android] [PATCH 10/24] AudioService: add support for the media list / playlist

Edward Wang edward.c.wang at compdigitec.com
Wed Aug 22 23:15:10 CEST 2012


---
 vlc-android/src/org/videolan/vlc/AudioService.java |   62 +++++++++++++++----
 .../org/videolan/vlc/AudioServiceController.java   |    8 ++-
 .../org/videolan/vlc/interfaces/IAudioService.aidl |    2 +-
 3 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 25c32f1..1094461 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -86,6 +86,8 @@ public class AudioService extends Service {
     private long mHeadsetDownTime = 0;
     private long mHeadsetUpTime = 0;
 
+    private boolean mRealPlaylist = false;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -426,7 +428,16 @@ public class AudioService extends Service {
                 return;
             }
         }
-        mLibVLC.readMedia(mCurrentMedia.getLocation(), true);
+        if(mRealPlaylist) {
+            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);
         showNotification();
         updateWidget(this);
@@ -440,7 +451,16 @@ public class AudioService extends Service {
             mCurrentMedia = mMediaList.get(index - 1);
         else
             return;
-        mLibVLC.readMedia(mCurrentMedia.getLocation(), true);
+        if(mRealPlaylist) {
+            if(mRepeating == RepeatType.None)
+                mLibVLC.previous();
+            else if(mRepeating == RepeatType.Once)
+                mLibVLC.playIndex(index);
+            else
+                mLibVLC.playIndex(mMediaList.indexOf(mCurrentMedia));
+        } else {
+            mLibVLC.readMedia(mCurrentMedia.getLocation(), true);
+        }
         mHandler.sendEmptyMessage(SHOW_PROGRESS);
         showNotification();
         updateWidget(this);
@@ -635,21 +655,30 @@ public class AudioService extends Service {
         }
 
         @Override
-        public void load(List<String> mediaPathList, int position)
+        public void load(List<String> mediaPathList, int position, boolean realPlaylist)
                 throws RemoteException {
+            mRealPlaylist = realPlaylist;
+
             Log.v(TAG, "Loading position " + ((Integer)position).toString() + " in " + mediaPathList.toString());
             mEventManager.addHandler(mEventHandler);
+
             mMediaList.clear();
             mPrevious.clear();
-            DatabaseManager db = DatabaseManager.getInstance(AudioService.this);
-            for (int i = 0; i < mediaPathList.size(); i++) {
-                String path = mediaPathList.get(i);
-                Media media = db.getMedia(AudioService.this, path);
-                if(media == null) {
-                    Log.v(TAG, "Creating on-the-fly Media object for " + path);
-                    media = new Media(path, false);
+
+            if(realPlaylist) {
+                for(int i = 0; i < mediaPathList.size(); i++)
+                    mMediaList.add(new Media(mediaPathList.get(i), false));
+            } else {
+                DatabaseManager db = DatabaseManager.getInstance(AudioService.this);
+                for (int i = 0; i < mediaPathList.size(); i++) {
+                    String path = mediaPathList.get(i);
+                    Media media = db.getMedia(AudioService.this, path);
+                    if(media == null) {
+                        Log.v(TAG, "Creating on-the-fly Media object for " + path);
+                        media = new Media(path, false);
+                    }
+                    mMediaList.add(media);
                 }
-                mMediaList.add(media);
             }
 
             if (mMediaList.size() > position) {
@@ -657,7 +686,11 @@ public class AudioService extends Service {
             }
 
             if (mCurrentMedia != null) {
-                mLibVLC.readMedia(mCurrentMedia.getLocation());
+                if(realPlaylist) {
+                    mLibVLC.playIndex(position);
+                } else {
+                    mLibVLC.readMedia(mCurrentMedia.getLocation());
+                }
                 showNotification();
                 updateWidget(AudioService.this);
             }
@@ -699,10 +732,13 @@ public class AudioService extends Service {
         @Override
         public void append(List<String> mediaPathList) throws RemoteException {
             if (mMediaList.size() == 0) {
-                load(mediaPathList, 0);
+                load(mediaPathList, 0, false);
                 return;
             }
 
+            if(mRealPlaylist) {
+                return;
+            }
             DatabaseManager db = DatabaseManager.getInstance(AudioService.this);
             for (int i = 0; i < mediaPathList.size(); i++) {
                 String path = mediaPathList.get(i);
diff --git a/vlc-android/src/org/videolan/vlc/AudioServiceController.java b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
index 3818862..ab9fbb0 100644
--- a/vlc-android/src/org/videolan/vlc/AudioServiceController.java
+++ b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
@@ -209,9 +209,13 @@ public class AudioServiceController implements IAudioPlayerControl {
     }
 
     public void load(List<String> mediaPathList, int position) {
+        load(mediaPathList, position, false);
+    }
+
+    public void load(List<String> mediaPathList, int position, boolean realPlaylist) {
         remoteProcedureCall(mAudioServiceBinder, Void.class, (Void)null, "load",
-                new Class<?>[] { List.class, int.class },
-                new Object[] { mediaPathList, position } );
+                new Class<?>[] { List.class, int.class, boolean.class },
+                new Object[] { mediaPathList, position, realPlaylist } );
     }
 
     public void append(List<String> mediaPathList) {
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
index 600dc42..a91ac43 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
@@ -30,7 +30,7 @@ interface IAudioService {
     void shuffle();
     void setTime(long time);
     String getCurrentMediaLocation();
-    void load(in List<String> mediaPathList, int position);
+    void load(in List<String> mediaPathList, int position, boolean realPlaylist);
     void append(in List<String> mediaPathList);
     List<String> getItems();
     String getItem();
-- 
1.7.5.4



More information about the Android mailing list