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

Edward Wang git at videolan.org
Tue Aug 28 17:12:42 CEST 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Wed Aug 22 17:15:10 2012 -0400| [51ef1ca2368d72ac412f4c8ba86de19eb33a5112] | committer: Jean-Baptiste Kempf

AudioService: add support for the media list / playlist

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 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 f8f3c27..5537c4b 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();
@@ -421,7 +423,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);
@@ -435,7 +446,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);
@@ -632,21 +652,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) {
@@ -654,7 +683,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);
             }
@@ -696,10 +729,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();



More information about the Android mailing list