2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
22 namespace Tizen.Content.MediaContent
25 /// Provides the commands to manage playlists in the database.
27 /// <seealso cref="Playlist"/>
28 /// <since_tizen> 4 </since_tizen>
29 public class PlaylistCommand : MediaCommand
32 /// Initializes a new instance of the <see cref="PlaylistCommand"/> class with the specified <see cref="MediaDatabase"/>.
34 /// <param name="database">A <see cref="MediaDatabase"/> that the commands run on.</param>
35 /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
36 /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed of.</exception>
37 /// <since_tizen> 4 </since_tizen>
38 public PlaylistCommand(MediaDatabase database) : base(database)
43 /// Retrieves the number of playlists.
45 /// <returns>The number of playlists.</returns>
46 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
47 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
48 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
49 /// <since_tizen> 4 </since_tizen>
56 /// Retrieves the number of playlists with the <see cref="CountArguments"/>.
58 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
59 /// <returns>The number of playlists.</returns>
60 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
61 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
62 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
63 /// <since_tizen> 4 </since_tizen>
64 public int Count(CountArguments arguments)
68 return CommandHelper.Count(Interop.Playlist.GetPlaylistCount, arguments);
72 /// Retrieves the play order of the member.
74 /// <param name="playlistId">The playlist ID.</param>
75 /// <param name="memberId">The member ID of the playlist.</param>
76 /// <returns>The order of the member in the playlist.</returns>
77 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
78 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
79 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
80 /// <exception cref="ArgumentOutOfRangeException">
81 /// <paramref name="playlistId"/> is less than or equal to zero.<br/>
83 /// <paramref name="memberId"/> is less than or equal to zero.
85 /// <since_tizen> 4 </since_tizen>
86 public int GetPlayOrder(int playlistId, int memberId)
92 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
93 "Playlist id can't be less than or equal to zero.");
98 throw new ArgumentOutOfRangeException(nameof(memberId), memberId,
99 "Member id can't be less than or equal to zero.");
102 Interop.Playlist.GetPlayOrder(playlistId, memberId, out var order).ThrowIfError("Failed to query");
108 /// Deletes a playlist from the database.
110 /// <privilege>http://tizen.org/privilege/content.write</privilege>
111 /// <param name="playlistId">The playlist ID to delete.</param>
112 /// <returns>true if the matched record was found and deleted, otherwise false.</returns>
113 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
114 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
115 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
116 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
117 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
118 /// <since_tizen> 4 </since_tizen>
119 public bool Delete(int playlistId)
125 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
126 "Playlist id can't be less than or equal to zero.");
129 if (Select(playlistId) == null)
134 CommandHelper.Delete(Interop.Playlist.Delete, playlistId);
139 /// Inserts the playlist into the database from the specified M3U file.
142 /// If you want to access an internal storage, you should add privilege http://tizen.org/privilege/mediastorage.<br/>
143 /// If you want to access an external storage, you should add privilege http://tizen.org/privilege/externalstorage.
145 /// <privilege>http://tizen.org/privilege/content.write</privilege>
146 /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
147 /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
148 /// <param name="name">The name of the playlist.</param>
149 /// <param name="path">The path to a M3U file to import.</param>
150 /// <returns>The <see cref="Playlist"/> instance that contains the record information inserted.</returns>
151 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
152 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
153 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
154 /// <exception cref="ArgumentNullException">
155 /// <paramref name="name"/> is null.<br/>
157 /// <paramref name="path"/> is null.
159 /// <exception cref="ArgumentException">
160 /// <paramref name="name"/> is a zero-length string.<br/>
162 /// <paramref name="path"/> is a zero-length string, contains only white space.
164 /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exists.</exception>
165 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
166 /// <since_tizen> 4 </since_tizen>
167 public Playlist InsertFromFile(string name, string path)
173 throw new ArgumentNullException(nameof(name));
176 if (name.Length == 0)
178 throw new ArgumentException("Playlist name can't be an empty string.");
181 ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path));
183 if (File.Exists(path) == false)
185 throw new FileNotFoundException("The specified path does not exists.", path);
188 IntPtr handle = IntPtr.Zero;
189 Interop.Playlist.ImportFromFile(path, name, out handle).ThrowIfError("Failed to insert");
193 return new Playlist(handle);
197 if (handle != IntPtr.Zero)
199 Interop.Playlist.Destroy(handle);
204 /// Exports the playlist to a M3U file.
207 /// If the file already exists in the file system, then it will be overwritten.<br/>
209 /// If you want to access an internal storage, you should add privilege http://tizen.org/privilege/mediastorage.<br/>
210 /// If you want to access an external storage, you should add privilege http://tizen.org/privilege/externalstorage.
212 /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
213 /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
214 /// <param name="playlistId">The playlist ID to export.</param>
215 /// <param name="path">The path to a M3U file.</param>
216 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
217 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
218 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
219 /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
220 /// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space.</exception>
221 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
222 /// <exception cref="RecordNotFoundException">No matching playlist exists.</exception>
223 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
224 /// <since_tizen> 4 </since_tizen>
225 public void ExportToFile(int playlistId, string path)
229 ValidationUtil.ValidateNotNullOrEmpty(path, nameof(path));
233 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
234 "Playlist id can't be less than or equal to zero.");
237 IntPtr handle = IntPtr.Zero;
240 Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query");
242 Interop.Playlist.ExportToFile(handle, path).ThrowIfError("Failed to export");
244 catch (ArgumentException)
246 // Native FW returns ArgumentException when there's no matched record.
247 throw new RecordNotFoundException("No matching playlist exists.");
251 if (handle != IntPtr.Zero)
253 Interop.Playlist.Destroy(handle);
259 /// Inserts the playlist into the database with the specified name.
261 /// <privilege>http://tizen.org/privilege/content.write</privilege>
262 /// <param name="name">The name of the playlist.</param>
263 /// <returns>The <see cref="Playlist"/> instance that contains the record information inserted.</returns>
264 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
265 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
266 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
267 /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
268 /// <exception cref="ArgumentException"><paramref name="name"/> is a zero-length string.</exception>
269 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
270 /// <since_tizen> 4 </since_tizen>
271 public Playlist Insert(string name)
273 return Insert(name, null);
277 /// Inserts the playlist into the database with the specified name and the thumbnail path.
279 /// <privilege>http://tizen.org/privilege/content.write</privilege>
280 /// <param name="name">The name of the playlist.</param>
281 /// <param name="thumbnailPath">The path of the thumbnail for the playlist. This value can be null.</param>
282 /// <returns>The <see cref="Playlist"/> instance that contains the record information inserted.</returns>
283 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
284 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
285 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
286 /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
287 /// <exception cref="ArgumentException"><paramref name="name"/> is a zero-length string.</exception>
288 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
289 /// <since_tizen> 4 </since_tizen>
290 public Playlist Insert(string name, string thumbnailPath)
296 throw new ArgumentNullException(nameof(name));
299 if (name.Length == 0)
301 throw new ArgumentException("Playlist name can't be an empty string.");
304 IntPtr handle = IntPtr.Zero;
305 Interop.Playlist.Create(out handle).ThrowIfError("Failed to insert");
309 Interop.Playlist.SetName(handle, name).ThrowIfError("Failed to insert");
311 if (thumbnailPath != null)
313 Interop.Playlist.SetThumbnailPath(handle, thumbnailPath).ThrowIfError("Failed to insert");
316 Interop.Playlist.Insert(handle).ThrowIfError("Failed to insert");
317 return new Playlist(handle);
321 if (handle != IntPtr.Zero)
323 Interop.Playlist.Destroy(handle);
329 /// Retrieves the playlists.
331 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
332 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
333 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
334 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
335 /// <since_tizen> 4 </since_tizen>
336 public MediaDataReader<Playlist> Select()
342 /// Retrieves the playlists with the <see cref="SelectArguments"/>.
344 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
345 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
346 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
347 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
348 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
349 /// <since_tizen> 4 </since_tizen>
350 public MediaDataReader<Playlist> Select(SelectArguments filter)
354 return CommandHelper.Select(filter, Interop.Playlist.ForeachPlaylistFromDb,
355 Playlist.FromHandle);
359 /// Retrieves the playlist with the specified playlist ID.
361 /// <param name="playlistId">The playlist ID to select.</param>
362 /// <returns>The <see cref="Playlist"/> instance if the matched record was found in the database, otherwise null.</returns>
363 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
364 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
365 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
366 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
367 /// <since_tizen> 4 </since_tizen>
368 public Playlist Select(int playlistId)
374 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
375 "Playlist id can't be less than or equal to zero.");
378 IntPtr handle = IntPtr.Zero;
382 Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query");
384 return new Playlist(handle);
386 catch (ArgumentException)
388 // Native FW returns ArgumentException when there's no matched record.
393 if (handle != IntPtr.Zero)
395 Interop.Playlist.Destroy(handle);
401 /// Retrieves the number of media information of the playlist.
403 /// <param name="playlistId">The playlist ID to count media added to the playlist.</param>
404 /// <returns>The number of media information.</returns>
405 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
406 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
407 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
408 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
409 /// <since_tizen> 4 </since_tizen>
410 public int CountMember(int playlistId)
412 return CountMember(playlistId, null);
416 /// Retrieves the number of media information of the playlist with the <see cref="CountArguments"/>.
418 /// <param name="playlistId">The playlist ID to count the media added to the playlist.</param>
419 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
420 /// <returns>The number of media information.</returns>
421 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
422 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
423 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
424 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
425 /// <since_tizen> 4 </since_tizen>
426 public int CountMember(int playlistId, CountArguments arguments)
432 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
433 "Playlist id can't be less than or equal to zero.");
436 return CommandHelper.Count(Interop.Playlist.GetMediaCountFromDb, playlistId, arguments);
440 private static List<PlaylistMember> GetMembers(int playlistId, SelectArguments arguments)
442 using (var filter = QueryArguments.ToNativeHandle(arguments))
444 Exception caught = null;
445 List<PlaylistMember> list = new List<PlaylistMember>();
447 Interop.Playlist.ForeachMediaFromDb(playlistId, filter, (memberId, mediaInfoHandle, _) =>
451 list.Add(new PlaylistMember(memberId, MediaInfo.FromHandle(mediaInfoHandle)));
460 }).ThrowIfError("Failed to query");
472 /// Retrieves the member ID of the media in the playlist.
474 /// <param name="playlistId">The playlist ID.</param>
475 /// <param name="mediaId">The media ID.</param>
476 /// <returns>The member ID if the member was found in the playlist, otherwise -1.</returns>
477 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
478 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
479 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
480 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
481 /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
482 /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception>
483 /// <since_tizen> 4 </since_tizen>
484 public int GetMemberId(int playlistId, string mediaId)
488 ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId));
492 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
493 "Playlist id can't be less than or equal to zero.");
496 var reader = SelectMember(playlistId, new SelectArguments()
498 FilterExpression = $"{MediaInfoColumns.Id}='{mediaId}'"
502 return reader.Current?.MemberId ?? -1;
506 /// Retrieves the media information of the playlist.
508 /// <param name="playlistId">The playlist ID to query with.</param>
509 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
510 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
511 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
512 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
513 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
514 /// <since_tizen> 4 </since_tizen>
515 public MediaDataReader<PlaylistMember> SelectMember(int playlistId)
517 return SelectMember(playlistId, null);
521 /// Retrieves the media information of the playlist with the <see cref="SelectArguments"/>.
523 /// <param name="playlistId">The playlist ID to query with.</param>
524 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
525 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
526 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
527 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
528 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
529 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
530 /// <since_tizen> 4 </since_tizen>
531 public MediaDataReader<PlaylistMember> SelectMember(int playlistId, SelectArguments filter)
537 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
538 "Playlist id can't be less than or equal to zero.");
541 return new MediaDataReader<PlaylistMember>(GetMembers(playlistId, filter));
545 /// Updates the playlist with the specified values.
547 /// <privilege>http://tizen.org/privilege/content.write</privilege>
548 /// <param name="playlistId">The playlist ID to update.</param>
549 /// <param name="values">The values for the update.</param>
550 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
551 /// <remarks>Only values set in the <see cref="PlaylistUpdateValues"/> are updated.</remarks>
552 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
553 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
554 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
555 /// <exception cref="ArgumentNullException"><paramref name="values"/> is null.</exception>
556 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
557 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
558 /// <since_tizen> 4 </since_tizen>
559 public bool Update(int playlistId, PlaylistUpdateValues values)
565 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
566 "Playlist id can't be less than or equal to zero.");
571 throw new ArgumentNullException(nameof(values));
574 if (CommandHelper.Count(
575 Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0)
580 Interop.Playlist.Create(out var handle).ThrowIfError("Failed to update");
584 if (values.Name != null)
586 Interop.Playlist.SetName(handle, values.Name).ThrowIfError("Failed to update");
589 if (values.ThumbnailPath != null)
591 Interop.Playlist.SetThumbnailPath(handle, values.ThumbnailPath).ThrowIfError("Failed to update");
594 Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to update");
599 if (handle != IntPtr.Zero)
601 Interop.Playlist.Destroy(handle);
607 /// Adds the media to the playlist.
609 /// <param name="playlistId">The playlist ID that the media will be added to.</param>
610 /// <param name="mediaId">The media ID to add to the playlist.</param>
611 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
612 /// <remarks>The invalid media ID will be ignored.</remarks>
613 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
614 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
615 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
616 /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
617 /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception>
618 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
619 /// <since_tizen> 4 </since_tizen>
620 public bool AddMember(int playlistId, string mediaId)
622 ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId));
624 return AddMembers(playlistId, new string[] { mediaId });
628 /// Adds the media set to the playlist.
630 /// <param name="playlistId">The playlist ID that the media will be added to.</param>
631 /// <param name="mediaIds">The collection of media ID to add to the playlist.</param>
632 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
633 /// <remarks>The invalid media IDs will be ignored.</remarks>
634 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
635 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
636 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
637 /// <exception cref="ArgumentNullException"><paramref name="mediaIds"/> is null.</exception>
638 /// <exception cref="ArgumentException">
639 /// <paramref name="mediaIds"/> has no element.<br/>
641 /// <paramref name="mediaIds"/> contains null value.<br/>
643 /// <paramref name="mediaIds"/> contains a zero-length string or white space.
645 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
646 /// <since_tizen> 4 </since_tizen>
647 public bool AddMembers(int playlistId, IEnumerable<string> mediaIds)
653 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
654 "Playlist id can't be less than or equal to zero.");
657 if (mediaIds == null)
659 throw new ArgumentNullException(nameof(mediaIds));
662 if (mediaIds.Count() == 0)
664 throw new ArgumentException("mediaIds has no element.", nameof(mediaIds));
667 if (CommandHelper.Count(
668 Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0)
673 IntPtr handle = IntPtr.Zero;
674 Interop.Playlist.Create(out handle).ThrowIfError("Failed to add member");
678 foreach (var mediaId in mediaIds)
682 throw new ArgumentException("Media id should not be null.", nameof(mediaIds));
685 if (string.IsNullOrWhiteSpace(mediaId))
687 throw new ArgumentException("Media id should not be empty.", nameof(mediaId));
690 Interop.Playlist.AddMedia(handle, mediaId).ThrowIfError("Failed to add member");
693 Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to add member");
698 if (handle != IntPtr.Zero)
700 Interop.Playlist.Destroy(handle);
706 /// Removes a member from the playlist.
708 /// <param name="playlistId">The playlist ID.</param>
709 /// <param name="memberId">The member ID to be removed.</param>
710 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
711 /// <remarks>The invalid ID will be ignored.</remarks>
712 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
713 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
714 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
715 /// <exception cref="ArgumentOutOfRangeException">
716 /// <paramref name="playlistId"/> is less than or equal to zero.<br/>
718 /// <paramref name="memberId"/> is less than or equal to zero.
720 /// <since_tizen> 4 </since_tizen>
721 public bool RemoveMember(int playlistId, int memberId)
725 throw new ArgumentOutOfRangeException(nameof(memberId), memberId,
726 "Member id can't be less than or equal to zero.");
729 return RemoveMembers(playlistId, new int[] { memberId });
733 /// Removes a media set from the playlist.
735 /// <param name="playlistId">The playlist ID.</param>
736 /// <param name="memberIds">The collection of member ID to remove from to the playlist.</param>
737 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
738 /// <remarks>The invalid IDs will be ignored.</remarks>
739 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
740 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
741 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
742 /// <exception cref="ArgumentNullException"><paramref name="memberIds"/> is null.</exception>
743 /// <exception cref="ArgumentException">
744 /// <paramref name="memberIds"/> has no element.<br/>
746 /// <paramref name="memberIds"/> contains a value which is less than or equal to zero.
748 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
749 /// <since_tizen> 4 </since_tizen>
750 public bool RemoveMembers(int playlistId, IEnumerable<int> memberIds)
756 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
757 "Playlist id can't be less than or equal to zero.");
760 if (memberIds == null)
762 throw new ArgumentNullException(nameof(memberIds));
765 if (memberIds.Count() == 0)
767 throw new ArgumentException("memberIds has no element.", nameof(memberIds));
770 if (CommandHelper.Count(
771 Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0)
776 IntPtr handle = IntPtr.Zero;
777 Interop.Playlist.Create(out handle).ThrowIfError("Failed to add member");
781 foreach (var memberId in memberIds)
785 throw new ArgumentException(nameof(memberIds),
786 "Member id can't be less than or equal to zero.");
789 Interop.Playlist.RemoveMedia(handle, memberId).ThrowIfError("Failed to add member");
792 Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to add member");
797 if (handle != IntPtr.Zero)
799 Interop.Playlist.Destroy(handle);
805 /// Updates a play order of the playlist.
807 /// <param name="playlistId">The playlist ID.</param>
808 /// <param name="playOrder">The <see cref="PlayOrder"/> to apply.</param>
809 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
810 /// <remarks>The <see cref="PlayOrder.MemberId"/> that is invalid will be ignored.</remarks>
811 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
812 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
813 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
814 /// <exception cref="ArgumentNullException"><paramref name="playOrder"/> is null.</exception>
815 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
816 /// <since_tizen> 4 </since_tizen>
817 public bool UpdatePlayOrder(int playlistId, PlayOrder playOrder)
819 if (playOrder == null)
821 throw new ArgumentNullException(nameof(playOrder));
823 return UpdatePlayOrders(playlistId, new PlayOrder[] { playOrder });
827 /// Updates play orders of the playlist.
829 /// <param name="playlistId">The playlist ID.</param>
830 /// <param name="orders">The collection of the <see cref="PlayOrder"/> to apply.</param>
831 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
832 /// <remarks>The <see cref="PlayOrder.MemberId"/> that is invalid will be ignored.</remarks>
833 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
834 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
835 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
836 /// <exception cref="ArgumentNullException"><paramref name="orders"/> is null.</exception>
837 /// <exception cref="ArgumentException">
838 /// <paramref name="orders"/> has no element.<br/>
840 /// <paramref name="orders"/> contains a null value.
842 /// <exception cref="ArgumentOutOfRangeException"><paramref name="playlistId"/> is less than or equal to zero.</exception>
843 /// <since_tizen> 4 </since_tizen>
844 public bool UpdatePlayOrders(int playlistId, IEnumerable<PlayOrder> orders)
850 throw new ArgumentOutOfRangeException(nameof(playlistId), playlistId,
851 "Playlist id can't be less than or equal to zero.");
856 throw new ArgumentNullException(nameof(orders));
859 if (orders.Count() == 0)
861 throw new ArgumentException("memberIds has no element.", nameof(orders));
864 if (CommandHelper.Count(
865 Interop.Playlist.GetPlaylistCount, $"{PlaylistColumns.Id}={playlistId}") == 0)
870 IntPtr handle = IntPtr.Zero;
871 Interop.Playlist.Create(out handle).ThrowIfError("Failed to add member");
875 foreach (var order in orders)
879 throw new ArgumentException(nameof(orders),
880 "orders should not contain null value.");
882 Interop.Playlist.SetPlayOrder(handle, order.MemberId, order.Value).ThrowIfError("Failed to add member");
885 Interop.Playlist.Update(playlistId, handle).ThrowIfError("Failed to add member");
890 if (handle != IntPtr.Zero)
892 Interop.Playlist.Destroy(handle);