diff options
author | Praveen Gattu <gattu.p@samsung.com> | 2016-05-25 17:53:34 +0530 |
---|---|---|
committer | Praveen Gattu <gattu.p@samsung.com> | 2016-05-30 16:01:36 +0530 |
commit | 2ab06a651a745942dd390f1cb5ac8628dfdf5007 (patch) | |
tree | 53ebc95d2958fd664f148aff62d2ec47a52ef68a /Tizen.Content/Tizen.Content.MediaContent/PlayList.cs | |
parent | 363292b46e40a161720b15c15e29c0f6f7977c10 (diff) | |
download | media-content-2ab06a651a745942dd390f1cb5ac8628dfdf5007.tar.gz media-content-2ab06a651a745942dd390f1cb5ac8628dfdf5007.tar.bz2 media-content-2ab06a651a745942dd390f1cb5ac8628dfdf5007.zip |
Fixed review comments and updated CSProj file.
Changed async apis.Incorporated SE review comments.
Change-Id: I4a7e912839f33a310bc88460c4e9a6b6ee0f0391
Signed-off-by: Praveen Gattu <gattu.p@samsung.com>
Diffstat (limited to 'Tizen.Content/Tizen.Content.MediaContent/PlayList.cs')
-rw-r--r-- | Tizen.Content/Tizen.Content.MediaContent/PlayList.cs | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/Tizen.Content/Tizen.Content.MediaContent/PlayList.cs b/Tizen.Content/Tizen.Content.MediaContent/PlayList.cs index 8fce886..e3caecd 100644 --- a/Tizen.Content/Tizen.Content.MediaContent/PlayList.cs +++ b/Tizen.Content/Tizen.Content.MediaContent/PlayList.cs @@ -22,6 +22,7 @@ namespace Tizen.Content.MediaContent /// </remarks> public class PlayList : ContentCollection { + private IDictionary<string, int> dictionary = new Dictionary<string, int>(); private IntPtr _playlistHandle; internal IntPtr Handle { @@ -35,6 +36,31 @@ namespace Tizen.Content.MediaContent } } + private void refreshPlaylistDictionary() + { + dictionary.Clear(); + MediaContentError res; + Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) => + { + Interop.MediaInformation.SafeMediaInformationHandle newHandle; + res = (MediaContentError)Interop.MediaInformation.Clone(out newHandle, mediaHandle); + if (res != MediaContentError.None) + { + throw MediaContentErrorFactory.CreateException(res, "Failed to clone media"); + } + + MediaInformation info = new MediaInformation(newHandle); + string mediaId; + Interop.MediaInformation.GetMediaId(newHandle, out mediaId); + dictionary.Add(mediaId, memberId); + }; + res = (MediaContentError)Interop.Playlist.ForeachMediaFromDb(Id, IntPtr.Zero, callback, IntPtr.Zero); + if (res != MediaContentError.None) + { + throw MediaContentErrorFactory.CreateException(res, "Failed to get playlist items"); + } + } + /// <summary> /// The ID of the media playlist /// </summary> @@ -103,7 +129,7 @@ namespace Tizen.Content.MediaContent /// <summary> /// The constructor to create a new playlist with the given name in the media database. /// </summary> - /// <param name="playListName">The name of the inserted playlist</param> + /// <param name="name">The name of the inserted playlist</param> public PlayList(string name) { Name = name; @@ -138,8 +164,14 @@ namespace Tizen.Content.MediaContent /// Removes the playlist members related with the media from the given playlist. /// </summary> /// <param name="mediaContent">The AudioContent object to be removed</param> - public void RemoveItem(int memberId) + public void RemoveItem(MediaInformation media) { + int memberId = -1; + dictionary.TryGetValue(media.MediaId, out memberId); + if (memberId == -1) { + refreshPlaylistDictionary(); + } + dictionary.TryGetValue(media.MediaId, out memberId); MediaContentError res = (MediaContentError)Interop.Playlist.RemoveMedia(_playlistHandle, memberId); if (res != MediaContentError.None) { @@ -181,17 +213,17 @@ namespace Tizen.Content.MediaContent /// Imports the playlist from m3u playlist file. /// </summary> /// <param name="name">The name of the playlist to save</param> - /// <param name="path">The path to import the playlist file</param> + /// <param name="filePath">The path to import the playlist file</param> /// <returns>The imported PlayList object</returns> - public static PlayList Import(string name, string path) + public static PlayList Import(string name, string filePath) { PlayList playList = null; IntPtr playlistHandle; - MediaContentError res = (MediaContentError)Interop.Playlist.ImportFromFile(name, path, out playlistHandle); + MediaContentError res = (MediaContentError)Interop.Playlist.ImportFromFile(name, filePath, out playlistHandle); if (res != MediaContentError.None) { - throw MediaContentErrorFactory.CreateException(res, "Failed to import playlist " + name + " from " + path); + throw MediaContentErrorFactory.CreateException(res, "Failed to import playlist " + name + " from " + filePath); } playList = new PlayList(name); playList._playlistHandle = playlistHandle; @@ -202,47 +234,14 @@ namespace Tizen.Content.MediaContent /// Exports the playlist to m3u playlist file. /// </summary> /// <returns>path The path to export the playlist</returns> - public static void Export(PlayList list, string path) - { - - MediaContentError res = (MediaContentError)Interop.Playlist.ExportToFile(list.Handle, path); - if (res != MediaContentError.None) - { - throw MediaContentErrorFactory.CreateException(res, "Failed to export playlist " + list.Name + " to " + path); - } - } - - /// <summary> - /// Gets the media content list for the given playlist member id. - /// </summary> - /// <param name="filter">The content filter</param> - /// <returns>Media content list</returns> - public Task<IDictionary<int, MediaInformation>> GetPlayListItemsAsync(ContentFilter filter) + public static void Export(PlayList list, string filePath) { - var tcs = new TaskCompletionSource<IDictionary<int, MediaInformation>>(); - - IDictionary<int, MediaInformation> dictionary = new Dictionary<int, MediaInformation>(); - IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero; - MediaContentError res; - Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) => - { - Interop.MediaInformation.SafeMediaInformationHandle newHandle ; - res = (MediaContentError)Interop.MediaInformation.Clone(out newHandle, mediaHandle); - if (res != MediaContentError.None) - { - throw MediaContentErrorFactory.CreateException(res, "Failed to clone media"); - } - MediaInformation info = new MediaInformation(newHandle); - dictionary.Add(memberId, info); - }; - res = (MediaContentError)Interop.Playlist.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero); + MediaContentError res = (MediaContentError)Interop.Playlist.ExportToFile(list.Handle, filePath); if (res != MediaContentError.None) { - throw MediaContentErrorFactory.CreateException(res, "Failed to get playlist items"); + throw MediaContentErrorFactory.CreateException(res, "Failed to export playlist " + list.Name + " to " + filePath); } - tcs.TrySetResult(dictionary); - return tcs.Task; } /// <summary> |