<div dir="ltr"><div>id == 0 means this is not a medialibrary media and I have to create one with addMedia.<br><br></div>Roger for the null check.<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 4, 2017 at 2:43 PM Hugo Beauzée-Luyssen <<a href="mailto:hugo@beauzee.fr">hugo@beauzee.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 01/03/2017 05:13 PM, Geoffrey Métais wrote:<br class="gmail_msg">
> vlc-android | branch: master | Geoffrey Métais <<a href="mailto:geoffrey.metais@gmail.com" class="gmail_msg" target="_blank">geoffrey.metais@gmail.com</a>> | Tue Jan  3 14:35:46 2017 +0100| [6d69478d6cd4db20c6a77a56732e7294d1074d3e] | committer: Geoffrey Métais<br class="gmail_msg">
><br class="gmail_msg">
> Add external media to playlists<br class="gmail_msg">
><br class="gmail_msg">
>> <a href="https://code.videolan.org/videolan/vlc-android/commit/6d69478d6cd4db20c6a77a56732e7294d1074d3e" rel="noreferrer" class="gmail_msg" target="_blank">https://code.videolan.org/videolan/vlc-android/commit/6d69478d6cd4db20c6a77a56732e7294d1074d3e</a><br class="gmail_msg">
> ---<br class="gmail_msg">
><br class="gmail_msg">
>  .../vlc/gui/dialogs/SavePlaylistDialog.java        | 22 +++++++++++++++++++---<br class="gmail_msg">
>  1 file changed, 19 insertions(+), 3 deletions(-)<br class="gmail_msg">
><br class="gmail_msg">
> diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java<br class="gmail_msg">
> index 64a2600..6483787 100644<br class="gmail_msg">
> --- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java<br class="gmail_msg">
> +++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java<br class="gmail_msg">
> @@ -148,16 +148,32 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi<br class="gmail_msg">
>                  if (addTracks) {<br class="gmail_msg">
>                      if (!exists)<br class="gmail_msg">
>                          playlist = mMedialibrary.createPlaylist(name);<br class="gmail_msg">
> -                    ids = new long[mTracks.size()];<br class="gmail_msg">
> -                    for (int i = 0 ; i < mNewTrack.size(); ++i)<br class="gmail_msg">
> +                    ids = new long[mNewTrack.size()];<br class="gmail_msg">
> +                    for (int i = 0 ; i < mNewTrack.size(); ++i) {<br class="gmail_msg">
>                          ids[i] = mNewTrack.get(i).getId();<br class="gmail_msg">
> +                        if (ids[i] == 0) {<br class="gmail_msg">
> +                            MediaWrapper media = mMedialibrary.getMedia(mNewTrack.get(i).getLocation());<br class="gmail_msg">
> +                            if (media != null && media.getId() != 0)<br class="gmail_msg">
<br class="gmail_msg">
A media returned from the medialibrary will always have an ID > 0<br class="gmail_msg">
<br class="gmail_msg">
> +                                ids[i] = media.getId();<br class="gmail_msg">
> +                            else<br class="gmail_msg">
> +                                ids[i] = mMedialibrary.addMedia(mNewTrack.get(i).getLocation()).getId();<br class="gmail_msg">
<br class="gmail_msg">
There's a thin possibility for addMedia to return a null media<br class="gmail_msg">
(unlikely, but theoretically possible)<br class="gmail_msg">
<br class="gmail_msg">
> +                        }<br class="gmail_msg">
> +                    }<br class="gmail_msg">
>                  } else { //Save a playlist<br class="gmail_msg">
>                      if (exists)<br class="gmail_msg">
>                          playlist.delete(mMedialibrary);<br class="gmail_msg">
>                      playlist = mMedialibrary.createPlaylist(name);<br class="gmail_msg">
>                      ids = new long[mTracks.size()];<br class="gmail_msg">
> -                    for (int i = 0; i < mTracks.size(); ++i)<br class="gmail_msg">
> +                    for (int i = 0; i < mTracks.size(); ++i) {<br class="gmail_msg">
>                          ids[i] = mTracks.get(i).getId();<br class="gmail_msg">
> +                        if (ids[i] == 0) {<br class="gmail_msg">
> +                            MediaWrapper media = mMedialibrary.getMedia(mNewTrack.get(i).getLocation());<br class="gmail_msg">
> +                            if (media != null && media.getId() != 0)<br class="gmail_msg">
> +                                ids[i] = media.getId();<br class="gmail_msg">
> +                            else<br class="gmail_msg">
> +                                ids[i] = mMedialibrary.addMedia(mNewTrack.get(i).getLocation()).getId();<br class="gmail_msg">
> +                        }<br class="gmail_msg">
> +                    }<br class="gmail_msg">
>                  }<br class="gmail_msg">
>                  playlist.append(mMedialibrary, ids);<br class="gmail_msg">
>                  if (mCallBack != null)<br class="gmail_msg">
><br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> Android mailing list<br class="gmail_msg">
> <a href="mailto:Android@videolan.org" class="gmail_msg" target="_blank">Android@videolan.org</a><br class="gmail_msg">
> <a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" class="gmail_msg" target="_blank">https://mailman.videolan.org/listinfo/android</a><br class="gmail_msg">
><br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Android mailing list<br class="gmail_msg">
<a href="mailto:Android@videolan.org" class="gmail_msg" target="_blank">Android@videolan.org</a><br class="gmail_msg">
<a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" class="gmail_msg" target="_blank">https://mailman.videolan.org/listinfo/android</a><br class="gmail_msg">
</blockquote></div>