[Android] Add external media to playlists

Geoffrey Métais geoffrey.metais at gmail.com
Wed Jan 4 18:45:25 CET 2017


id == 0 means this is not a medialibrary media and I have to create one
with addMedia.

Roger for the null check.

On Wed, Jan 4, 2017 at 2:43 PM Hugo Beauzée-Luyssen <hugo at beauzee.fr> wrote:

> On 01/03/2017 05:13 PM, Geoffrey Métais wrote:
> > 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)
>
> A media returned from the medialibrary will always have an ID > 0
>
> > +                                ids[i] = media.getId();
> > +                            else
> > +                                ids[i] =
> mMedialibrary.addMedia(mNewTrack.get(i).getLocation()).getId();
>
> There's a thin possibility for addMedia to return a null media
> (unlikely, but theoretically possible)
>
> > +                        }
> > +                    }
> >                  } 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)
> >
> > _______________________________________________
> > Android mailing list
> > Android at videolan.org
> > https://mailman.videolan.org/listinfo/android
> >
>
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20170104/a18254ad/attachment.html>


More information about the Android mailing list