[Android] Add external media to playlists

Geoffrey Métais git at videolan.org
Tue Jan 3 17:13:11 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan  3 14:35:46 2017 +0100| [6d69478d6cd4db20c6a77a56732e7294d1074d3e] | committer: Geoffrey Métais

Add external media to playlists

> https://code.videolan.org/videolan/vlc-android/commit/6d69478d6cd4db20c6a77a56732e7294d1074d3e
---

 .../vlc/gui/dialogs/SavePlaylistDialog.java        | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
index 64a2600..6483787 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -148,16 +148,32 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
                 if (addTracks) {
                     if (!exists)
                         playlist = mMedialibrary.createPlaylist(name);
-                    ids = new long[mTracks.size()];
-                    for (int i = 0 ; i < mNewTrack.size(); ++i)
+                    ids = new long[mNewTrack.size()];
+                    for (int i = 0 ; i < mNewTrack.size(); ++i) {
                         ids[i] = mNewTrack.get(i).getId();
+                        if (ids[i] == 0) {
+                            MediaWrapper media = mMedialibrary.getMedia(mNewTrack.get(i).getLocation());
+                            if (media != null && media.getId() != 0)
+                                ids[i] = media.getId();
+                            else
+                                ids[i] = mMedialibrary.addMedia(mNewTrack.get(i).getLocation()).getId();
+                        }
+                    }
                 } else { //Save a playlist
                     if (exists)
                         playlist.delete(mMedialibrary);
                     playlist = mMedialibrary.createPlaylist(name);
                     ids = new long[mTracks.size()];
-                    for (int i = 0; i < mTracks.size(); ++i)
+                    for (int i = 0; i < mTracks.size(); ++i) {
                         ids[i] = mTracks.get(i).getId();
+                        if (ids[i] == 0) {
+                            MediaWrapper media = mMedialibrary.getMedia(mNewTrack.get(i).getLocation());
+                            if (media != null && media.getId() != 0)
+                                ids[i] = media.getId();
+                            else
+                                ids[i] = mMedialibrary.addMedia(mNewTrack.get(i).getLocation()).getId();
+                        }
+                    }
                 }
                 playlist.append(mMedialibrary, ids);
                 if (mCallBack != null)



More information about the Android mailing list