Fixed bugs.Modified bookmark and face property access flow.
authorPraveen Gattu <gattu.p@samsung.com>
Mon, 6 Jun 2016 05:43:20 +0000 (11:13 +0530)
committerAditya <a.aswani@samsung.com>
Tue, 14 Jun 2016 13:23:41 +0000 (18:53 +0530)
Code Formatter
Change-Id: Idbd8a200e95f54b7433ab31a7a34610e86d5b0e5
Signed-off-by: Praveen Gattu <gattu.p@samsung.com>
19 files changed:
Tizen.Content/Interop/Interop.MediaFolder.cs
Tizen.Content/Interop/Interop.MediaPlaylist.cs
Tizen.Content/Interop/Interop.MediaStorage.cs
Tizen.Content/Tizen.Content.MediaContent/Album.cs
Tizen.Content/Tizen.Content.MediaContent/AudioInformation.cs
Tizen.Content/Tizen.Content.MediaContent/ContentCollection.cs
Tizen.Content/Tizen.Content.MediaContent/ContentDatabase.cs
Tizen.Content/Tizen.Content.MediaContent/ContentFilter.cs
Tizen.Content/Tizen.Content.MediaContent/ContentManager.cs
Tizen.Content/Tizen.Content.MediaContent/ImageInformation.cs [changed mode: 0644->0755]
Tizen.Content/Tizen.Content.MediaContent/MediaBookmark.cs
Tizen.Content/Tizen.Content.MediaContent/MediaContentErrorFactory.cs
Tizen.Content/Tizen.Content.MediaContent/MediaFace.cs
Tizen.Content/Tizen.Content.MediaContent/MediaFolder.cs
Tizen.Content/Tizen.Content.MediaContent/MediaInformation.cs
Tizen.Content/Tizen.Content.MediaContent/PlayList.cs
Tizen.Content/Tizen.Content.MediaContent/Storage.cs
Tizen.Content/Tizen.Content.MediaContent/Tag.cs
Tizen.Content/Tizen.Content.MediaContent/VideoInformation.cs

index a837138..671c205 100644 (file)
@@ -59,7 +59,7 @@ internal static partial class Interop
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate bool MediaFolderCallback(IntPtr folderHandle, IntPtr data);
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate void MediaInfoCallback(Interop.MediaInformation.SafeMediaInformationHandle mediaInformation, IntPtr data);
+        internal delegate bool MediaInfoCallback(IntPtr handle, IntPtr data);
 
         [DllImport(Libraries.MediaContent, EntryPoint = "media_folder_foreach_folder_from_db")]
         internal static extern int ForeachFolderFromDb(IntPtr filter, MediaFolderCallback callback, IntPtr user_data);
index 2488afc..58b7024 100644 (file)
@@ -68,7 +68,7 @@ internal static partial class Interop
         internal delegate bool MediaPlaylistCallback(IntPtr playListHandle, IntPtr data);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate void PlaylistMemberCallback(int playListMemberId, IntPtr mediaInformation, IntPtr data);
+        internal delegate bool PlaylistMemberCallback(int playListMemberId, IntPtr mediaInformation, IntPtr data);
 
         [DllImport(Libraries.MediaContent, EntryPoint = "media_playlist_foreach_playlist_from_db")]
         internal static extern int ForeachPlaylistFromDb(IntPtr filter, MediaPlaylistCallback callback, IntPtr user_data);
index 0fe8c68..411b5b8 100644 (file)
@@ -38,7 +38,7 @@ internal static partial class Interop
         internal delegate bool MediaStorageCallback(IntPtr mediaStorageHandle, IntPtr data);
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        internal delegate void MediaInfoCallback(Interop.MediaInformation.SafeMediaInformationHandle mediaInformation, IntPtr data);
+        internal delegate bool MediaInfoCallback(IntPtr mediaInformation, IntPtr data);
 
         [DllImport(Libraries.MediaContent, EntryPoint = "media_storage_foreach_storage_from_db")]
         internal static extern int ForeachStorageFromDb(IntPtr filter, MediaStorageCallback callback, IntPtr user_data);
index bd4ec1c..1e82819 100644 (file)
@@ -141,9 +141,9 @@ namespace Tizen.Content.MediaContent
                     throw MediaContentErrorFactory.CreateException(res, "Failed to clone media");
                 }
 
-              MediaInformation info = new MediaInformation(newHandle);
-              mediaContents.Add(info);
-              return true;
+                MediaInformation info = new MediaInformation(newHandle);
+                mediaContents.Add(info);
+                return true;
             };
             res = (MediaContentError)Interop.Group.MediaAlbumForeachMediaFromDb(Id, handle, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
index 11b06a1..00b8c8d 100644 (file)
@@ -15,6 +15,7 @@ using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading.Tasks;
+using System.Collections.ObjectModel;
 
 namespace Tizen.Content.MediaContent
 {
@@ -386,6 +387,92 @@ namespace Tizen.Content.MediaContent
             }
         }
 
+        /// <summary>
+        /// Gets the number of bookmarks for the passed filter in the given media ID from the media database.
+        /// </summary>
+        /// <returns>
+        /// int count</returns>
+        /// <param name="filter">The Filter for matching BookMarks</param>
+        public int GetMediaBookMarkCount(ContentFilter filter)
+        {
+            int count = 0;
+            IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
+            MediaContentError result = (MediaContentError)Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count);
+            if (result != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(result, "Error Occured with error code: ");
+            }
+            return count;
+        }
+
+        /// <summary>
+        /// Iterates through the media bookmark in the given media info from the media database.
+        /// </summary>
+        /// <returns>
+        /// Task to get all the BookMarks </returns>
+        /// <param name="filter"> filter for the Tags</param>
+        public Task<IEnumerable<MediaBookmark>> GetMediaBookmarksAsync(ContentFilter filter)
+        {
+            var task = new TaskCompletionSource<IEnumerable<MediaBookmark>>();
+            MediaContentError result;
+            Collection<MediaBookmark> coll = new Collection<MediaBookmark>();
+            IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
+            Interop.MediaInformation.MediaBookMarkCallback bookmarksCallback = (IntPtr handle, IntPtr userData) =>
+            {
+                IntPtr newHandle;
+                result = (MediaContentError)Interop.MediaBookmark.Clone(out newHandle, handle);
+                if (result != MediaContentError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to clone Tag");
+                }
+                MediaBookmark bookmark = new MediaBookmark(newHandle);
+                coll.Add(bookmark);
+                return true;
+            };
+            result = (MediaContentError)Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, bookmarksCallback, IntPtr.Zero);
+            if (result != MediaContentError.None)
+            {
+                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
+            }
+            task.SetResult(coll);
+            return task.Task;
+        }
+
+        /// <summary>
+        /// Adds a bookmark to the audio
+        /// </summary>
+        /// <param name="offset">Offset of the audio in seconds</param>
+        /// <param name="thumbnailPath">Thumbnail path for the bookmark</param>
+        /// <returns></returns>
+        public async Task<MediaBookmark> AddBookmark(uint offset)
+        {
+            MediaBookmark result = null;
+            ContentManager.Database.Insert(MediaId, offset, null);
+            ContentFilter bookmarkfilter = new ContentFilter();
+            bookmarkfilter.Condition = "BOOKMARK_MARKED_TIME = " + offset;
+            IEnumerable<MediaBookmark> bookmarksList = null;
+            bookmarksList = await GetMediaBookmarksAsync(bookmarkfilter);
+            foreach (MediaBookmark bookmark in bookmarksList)
+            {
+                if (bookmark.Offset == offset)
+                {
+                    result = bookmark;
+                    break;
+                }
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// Deletes a bookmark from the media database.
+        /// For other types Unsupported exception is thrown.
+        /// </summary>
+        /// <param name="bookmark">The bookmark to be deleted</param>
+        public void DeleteBookmark(MediaBookmark bookmark)
+        {
+            ContentManager.Database.Delete(bookmark);
+        }
+
         internal IntPtr AudioHandle
         {
             get
index 4457656..e8f9529 100644 (file)
@@ -6,13 +6,14 @@
 /// it only in accordance with the terms of the license agreement
 /// you entered into with Samsung.
 
+
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
 
 namespace Tizen.Content.MediaContent
 {
-    public abstract class ContentCollection :IDisposable
+    public abstract class ContentCollection : IDisposable
     {
         /// <summary>
         /// Gets the media count for this content store matching the passed filter
index 7276960..ec232f9 100644 (file)
@@ -26,6 +26,7 @@ using System.Threading.Tasks;
 /// from the media content service.
 /// </remarks>
 
+
 namespace Tizen.Content.MediaContent
 {
     /// <summary>
@@ -34,33 +35,32 @@ namespace Tizen.Content.MediaContent
     /// </summary>
     public class ContentDatabase
     {
-        private bool s_isConnected = false;
+        private bool _isConnected = false;
         internal ContentDatabase()
         {
-
         }
         internal void ConnectToDB()
         {
-            if (!s_isConnected)
+            if (!_isConnected)
             {
                 MediaContentError err = (MediaContentError)Interop.Content.Connect();
                 if (err != MediaContentError.None)
                 {
                     throw MediaContentErrorFactory.CreateException(err, "failed to connect to db.");
                 }
-                s_isConnected = true;
+                _isConnected = true;
             }
         }
         private void DisconnectFromDB()
         {
-            if (s_isConnected)
+            if (_isConnected)
             {
                 MediaContentError err = (MediaContentError)Interop.Content.Disconnect();
                 if (err != MediaContentError.None)
                 {
                     throw MediaContentErrorFactory.CreateException(err, "failed to disconnect to db.");
                 }
-                s_isConnected = false;
+                _isConnected = false;
             }
         }
 
@@ -110,7 +110,7 @@ namespace Tizen.Content.MediaContent
         /// <param name="type">The content source type. Available types: Folder, Storage, MediaBookmark, Album, Playlist, Tag</param>
         /// <param name="filter">The media filter</param>
         /// <returns>The count of contents present in the media database for a ContentSourceType</returns>
-        public int GetCount<T>(ContentFilter filter) where T :  class
+        public int GetCount<T>(ContentFilter filter) where T : class
         {
             int count = 0;
             IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
@@ -175,13 +175,13 @@ namespace Tizen.Content.MediaContent
             MediaContentError error = MediaContentError.None;
             ConnectToDB();
             MediaInformation result;
-                Interop.MediaInformation.SafeMediaInformationHandle mediaHandle;
-                error = (MediaContentError)Interop.MediaInformation.GetMediaFromDB(id, out mediaHandle);
-                if (error != MediaContentError.None)
-                {
-                    throw MediaContentErrorFactory.CreateException(error, "Failed to get the media information from the database");
-                }
-                result = new MediaInformation(mediaHandle);
+            Interop.MediaInformation.SafeMediaInformationHandle mediaHandle;
+            error = (MediaContentError)Interop.MediaInformation.GetMediaFromDB(id, out mediaHandle);
+            if (error != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(error, "Failed to get the media information from the database");
+            }
+            result = new MediaInformation(mediaHandle);
             return result;
         }
 
@@ -428,12 +428,12 @@ namespace Tizen.Content.MediaContent
         {
             ConnectToDB();
             var task = new TaskCompletionSource<IEnumerable<T>>();
-            if(typeof(T) == typeof(MediaInformation))
+            if (typeof(T) == typeof(MediaInformation))
             {
                 IEnumerable<MediaInformation> mediaList = GetMediaInformations(filter);
                 task.TrySetResult((IEnumerable<T>)mediaList);
             }
-            if (typeof(T) == typeof(Album))
+            else if (typeof(T) == typeof(Album))
             {
                 List<Album> collectionList = ForEachAlbum(filter);
                 task.TrySetResult((IEnumerable<T>)collectionList);
@@ -587,7 +587,7 @@ namespace Tizen.Content.MediaContent
             {
                 result = (MediaContentError)Interop.Tag.DeleteFromDb(((Tag)contecollection).Id);
             }
-            if (type == typeof(PlayList))
+            else if (type == typeof(PlayList))
             {
                 result = (MediaContentError)Interop.Playlist.DeleteFromDb(((PlayList)contecollection).Id);
             }
@@ -599,12 +599,7 @@ namespace Tizen.Content.MediaContent
                 throw MediaContentErrorFactory.CreateException(result, "failed to Delete ContentCollection from DB");
         }
 
-        /// <summary>
-        /// Deletes a bookmark from the media database.
-        /// For other types Unsupported exception is thrown.
-        /// </summary>
-        /// <param name="bookmark">The bookmark to be deleted</param>
-        public void Delete(MediaBookmark bookmark)
+        internal void Delete(MediaBookmark bookmark)
         {
             ConnectToDB();
             MediaContentError result = MediaContentError.None;
@@ -613,12 +608,7 @@ namespace Tizen.Content.MediaContent
                 throw MediaContentErrorFactory.CreateException(result, "failed to Delete bookmark from DB");
         }
 
-        /// <summary>
-        /// Deletes a MediaFace from the media database.
-        /// For other types Unsupported exception is thrown.
-        /// </summary>
-        /// <param name="face">The face instance to be deleted</param>
-        public void Delete(MediaFace face)
+        internal void Delete(MediaFace face)
         {
             ConnectToDB();
             MediaContentError result = MediaContentError.None;
@@ -641,11 +631,11 @@ namespace Tizen.Content.MediaContent
             {
                 result = (MediaContentError)Interop.Tag.UpdateToDb(((Tag)contentCollection).Handle);
             }
-            if (type == typeof(PlayList))
+            else if (type == typeof(PlayList))
             {
                 result = (MediaContentError)Interop.Playlist.UpdateToDb(((PlayList)contentCollection).Handle);
             }
-            if (type == typeof(MediaFolder))
+            else if (type == typeof(MediaFolder))
             {
                 result = (MediaContentError)Interop.Folder.UpdateToDb(((MediaFolder)contentCollection).Handle);
             }
@@ -692,11 +682,7 @@ namespace Tizen.Content.MediaContent
                 throw MediaContentErrorFactory.CreateException(result, "Failed to update DB");
         }
 
-        /// <summary>
-        /// Updates a media face instance in the media database
-        /// </summary>
-        /// <param name="mediaInfo">The MediaFace object to be updated</param>
-        public void Update(MediaFace face)
+        internal void Update(MediaFace face)
         {
             ConnectToDB();
             Type type = face.GetType();
@@ -721,41 +707,34 @@ namespace Tizen.Content.MediaContent
                 result = (MediaContentError)Interop.Tag.InsertToDb(((Tag)contentCollection).Name, out handle);
                 ((Tag)contentCollection).Handle = handle;
             }
-            if (type == typeof(PlayList))
+            else if (type == typeof(PlayList))
             {
+                Console.WriteLine("Playlist insert");
                 result = (MediaContentError)Interop.Playlist.InsertToDb(((PlayList)contentCollection).Name, out handle);
                 ((PlayList)contentCollection).Handle = handle;
             }
             else
             {
-                result = MediaContentError.InvalidOperation;
+                Console.WriteLine("Inalid insert");
+                result = MediaContentError.InavlidParameter;
             }
             if (result != MediaContentError.None)
             {
                 throw MediaContentErrorFactory.CreateException(result, "Failed to insert collection to the database");
             }
-
         }
 
-        /// <summary>
-        /// Inserts a MediaBookMark item to the media database
-        /// </summary>
-        /// <param name="bookmark">The MediaBookmark item to be inserted</param>
-        public void Insert(MediaBookmark bookmark)
+        internal void Insert(string mediaId, uint offset, string thumbnailPath)
         {
             ConnectToDB();
-            MediaContentError  result = (MediaContentError)Interop.MediaBookmark.InsertToDb(((MediaBookmark)bookmark).MediaId, ((MediaBookmark)bookmark).Offset, ((MediaBookmark)bookmark).ThumbnailPath);
+            MediaContentError result = (MediaContentError)Interop.MediaBookmark.InsertToDb(mediaId, offset, thumbnailPath);
             if (result != MediaContentError.None)
             {
-                throw MediaContentErrorFactory.CreateException(result, "Failed to insert collection to the database");
+                throw MediaContentErrorFactory.CreateException(result, "Failed to insert bookmark to the database");
             }
         }
 
-        /// <summary>
-        /// Inserts a MediaFace item to the media database
-        /// </summary>
-        /// <param name="face">The MediaFace item to be inserted</param>
-        public void Insert(MediaFace face)
+        internal void Insert(MediaFace face)
         {
             ConnectToDB();
             MediaContentError result = (MediaContentError)Interop.Face.InsertToDb(((MediaFace)face).Handle);
index 10242bc..367244e 100644 (file)
@@ -66,7 +66,6 @@ namespace Tizen.Content.MediaContent
             {
                 return _filterHandle;
             }
-
         }
         /// <summary>
         /// The start position of the given filter Starting from zero.
index eb95db8..52281ed 100644 (file)
@@ -9,8 +9,10 @@
 
 using System;
 using System.Collections.Generic;
-using System.Threading;
 using System.Threading.Tasks;
+using System.IO;
+using System.Threading;
+
 /// <summary>
 /// The Media Content API provides functions, enumerations used in the entire Content Service.
 /// </summary>
@@ -35,7 +37,7 @@ namespace Tizen.Content.MediaContent
     /// </summary>
     public static class ContentManager
     {
-        private static ContentDatabase s_contentDB = new ContentDatabase();
+        private static readonly ContentDatabase s_contentDB = new ContentDatabase();
         public static ContentDatabase Database
         {
             get
@@ -45,20 +47,6 @@ namespace Tizen.Content.MediaContent
         }
 
         /// <summary>
-        /// Requests to cancel the media folder scanning.
-        /// </summary>
-        /// <param name="folderPath">The folder path</param>
-        public static void CancelScanningFolder(string folderPath)
-        {
-            MediaContentError result = (MediaContentError)Interop.Content.CancelScanFolder(folderPath);
-            if (result != MediaContentError.None)
-            {
-                throw MediaContentErrorFactory.CreateException(result, "Failed scan");
-            }
-        }
-
-
-        /// <summary>
         /// Requests to scan a media file.
         /// </summary>
         /// <param name="filePath">The file path</param>
@@ -108,21 +96,130 @@ namespace Tizen.Content.MediaContent
         /// The sub folders are also scanned,if there are sub folders in that folder.
         /// If any folder must not be scanned, a blank file ".scan_ignore" has to be created in that folder.
         /// </remarks>
-        public static Task StartScanningFolderAsync(string folderPath, bool recursive = true)
+        public static Task ScanFolderAsync(string folderPath, bool recursive = true)
         {
             var task = new TaskCompletionSource<int>();
+
             Interop.Content.MediaScanCompletedCallback scanCompleted = (MediaContentError scanResult, IntPtr data) =>
             {
-                Console.WriteLine("Scan Result: "+ scanResult);
+                if (scanResult != MediaContentError.None)
+                {
+                    task.SetException(MediaContentErrorFactory.CreateException(scanResult, "Failed scan"));
+                }
                 task.SetResult((int)scanResult);
             };
+            DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(folderPath));
+            MediaContentError result = MediaContentError.None;
+            if (dir.Exists)
+            {
+                result = (MediaContentError)Interop.Content.ScanFolder(folderPath, recursive, scanCompleted, IntPtr.Zero);
+            }
+            else
+            {
+                result = MediaContentError.InavlidParameter;
+                task.SetException(MediaContentErrorFactory.CreateException(result, "Scan directory does not exist"));
+            }
+            if (result != MediaContentError.None)
+            {
+                task.SetException(MediaContentErrorFactory.CreateException(result, "Failed scan"));
+            }
+            return task.Task;
+        }
 
-            MediaContentError result = (MediaContentError)Interop.Content.ScanFolder(folderPath, recursive, scanCompleted, IntPtr.Zero);
+        internal static Interop.Content.MediaScanCompletedCallback scanCompleted = null;
+        internal static Object l = new Object();
+        /// <summary>
+        /// Requests to scan a media folder, asynchronously.
+        /// </summary>
+        /// <param name="folderPath">The folder path</param>
+        /// <remarks>
+        /// This function requests to scan a media folder to the media server with given completed callback function.
+        /// ContentScanCompleted event will be truggered when the scanning is finished.
+        /// The sub folders are also scanned,if there are sub folders in that folder.
+        /// If any folder must not be scanned, a blank file ".scan_ignore" has to be created in that folder.
+        /// </remarks>
+        public static Task ScanFolderAsync(string folderPath, CancellationToken cancellationToken, bool recursive = true)
+        {
+            var task = new TaskCompletionSource<int>();
+            bool taskCompleted = false;
+
+            cancellationToken.Register(() =>
+            {
+                Tizen.Log.Info("TCT", "Register ThreadId: " + Thread.CurrentThread.ManagedThreadId);
+
+                lock (l)
+                {
+                    Tizen.Log.Info("TCT", "Cancellation delegate: Taking Lock on l");
+                    if (!taskCompleted)
+                    {
+                        taskCompleted = true;
+                        Log.Info("TCT", "Cancellation requested, Trying to stop scan");
+                        MediaContentError res = (MediaContentError)Interop.Content.CancelScanFolder(folderPath);
+                        Log.Info("TCT", "CancelScanFolder executed. ");
+
+                        if (res != MediaContentError.None)
+                        {
+                            Tizen.Log.Info("TCT", "Failed CancelScanFolder. Error: " + res);
+                        }
+                        else {
+                            Tizen.Log.Info("TCT", "Folder scan was successfully cancelled. CancelScanFolder was successfully executed.");
+                            task.SetCanceled();
+                        }
+                    }
+                    else {
+                        Tizen.Log.Info("TCT", "Request rejected. FolderScan already completed");
+                    }
+                    Tizen.Log.Info("TCT", "Cancellation delegate: Releasing lock on l");
+                }
+            });
+            scanCompleted = (MediaContentError scanResult, IntPtr data) =>
+            {
+                Tizen.Log.Info("TCT", "Scan Callback ScanResult: " + scanResult);
+                Tizen.Log.Info("TCT", "Scan Callback ThreadId: " + Thread.CurrentThread.ManagedThreadId);
+                lock (l)
+                {
+                    Tizen.Log.Info("TCT", "Scan completed cb: Taking Lock on l");
+                    if (!taskCompleted)
+                    {
+                        taskCompleted = true;
+                        Tizen.Log.Info("TCT", "Scan folder callback recieved.");
+                        if (scanResult != MediaContentError.None)
+                        {
+                            Tizen.Log.Info("TCT", "Scan folder callback got error in scanResult. Error: " + scanResult);
+                            task.SetException(MediaContentErrorFactory.CreateException(scanResult, "Failed scan"));
+                        }
+                        Tizen.Log.Info("TCT", "Scan folder callback does not have any error");
+
+                        task.SetResult((int)scanResult);
+                    }
+                    else {
+                        Tizen.Log.Info("TCT", "ScanFolder task already cancelled/completed");
+                    }
+                    Tizen.Log.Info("TCT", "Scan completed cb: Releasing Lock on l");
+                }
+            };
+
+            DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(folderPath));
+            MediaContentError result = MediaContentError.None;
+            if (dir.Exists)
+            {
+                Tizen.Log.Info("TCT", "Scan folder start");
+                result = (MediaContentError)Interop.Content.ScanFolder(folderPath, recursive, scanCompleted, IntPtr.Zero);
+                Tizen.Log.Info("TCT", "Scan folder end");
+            }
+            else
+            {
+                result = MediaContentError.InavlidParameter;
+                task.SetException(MediaContentErrorFactory.CreateException(result, "Scan directory does not exist"));
+            }
             if (result != MediaContentError.None)
             {
-                throw MediaContentErrorFactory.CreateException(result, "Failed scan");
+                task.SetException(MediaContentErrorFactory.CreateException(result, "Failed scan: " + result));
             }
+            Tizen.Log.Info("TCT", "Before task return");
+
             return task.Task;
+
         }
 
         /// <summary>
@@ -138,12 +235,16 @@ namespace Tizen.Content.MediaContent
             MediaContentError res = MediaContentError.None;
             Interop.MediaInformation.MediaInsertCompletedCallback callback = (MediaContentError error, IntPtr userData) =>
             {
+                if (error != MediaContentError.None)
+                {
+                    task.SetException(MediaContentErrorFactory.CreateException(res, "Failed to add batch media"));
+                }
                 task.SetResult((int)error);
             };
             res = (MediaContentError)Interop.MediaInformation.BatchInsert(paths, paths.Length, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
             {
-                Log.Warn(Globals.LogTag, "Failed to add media information to the database");
+                task.SetException(MediaContentErrorFactory.CreateException(res, "Failed to add batch media"));
             }
             return task.Task;
         }
@@ -161,12 +262,16 @@ namespace Tizen.Content.MediaContent
             MediaContentError res = MediaContentError.None;
             Interop.MediaInformation.MediaInsertBurstShotCompletedCallback callback = (MediaContentError error, IntPtr userData) =>
             {
+                if (error != MediaContentError.None)
+                {
+                    task.SetException(MediaContentErrorFactory.CreateException(res, "Failed to add burst shots to db"));
+                }
                 task.SetResult((int)error);
             };
             res = (MediaContentError)Interop.MediaInformation.BurstShotInsert(paths, paths.Length, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
             {
-                Log.Warn(Globals.LogTag, "Failed to add burst shots to the database");
+                task.SetException(MediaContentErrorFactory.CreateException(res, "Failed to add burst shots to db"));
             }
             return task.Task;
         }
@@ -187,9 +292,9 @@ namespace Tizen.Content.MediaContent
             res = (MediaContentError)Interop.MediaInformation.BatchDelete(handle);
             if (res != MediaContentError.None)
             {
-                Log.Warn(Globals.LogTag, "Failed to delete media from the database");
+                task.SetException(MediaContentErrorFactory.CreateException(res, "Failed to delete batch media from db"));
             }
-            task.SetResult(0);
+            task.SetResult((int)res);
             return task.Task;
         }
     }
old mode 100644 (file)
new mode 100755 (executable)
index 7221c03..79ae9f8
@@ -14,6 +14,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Collections.ObjectModel;
 
 namespace Tizen.Content.MediaContent
 {
@@ -234,6 +235,80 @@ namespace Tizen.Content.MediaContent
             }
         }
 
+        /// <summary>
+        /// Iterates through the media files with optional media_id in the given face face from the media database.
+        /// </summary>
+        /// <returns>
+        /// Task to get all the MediaFaces </returns>
+        /// <param name="filter"> filter for the Tags</param>
+        public Task<IEnumerable<MediaFace>> GetMediaFacesAsync(ContentFilter filter)
+        {
+            var task = new TaskCompletionSource<IEnumerable<MediaFace>>();
+            Collection<MediaFace> coll = new Collection<MediaFace>();
+            Interop.MediaInformation.MediaFaceCallback faceCallback = (IntPtr facehandle, IntPtr userData) =>
+            {
+                MediaFace face = new MediaFace(facehandle);
+                coll.Add(face);
+                return true;
+            };
+            int result = Interop.MediaInformation.GetAllFaces(MediaId, filter.Handle, faceCallback, IntPtr.Zero);
+            if ((MediaContentError)result != MediaContentError.None)
+            {
+                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
+            }
+            task.SetResult(coll);
+            return task.Task;
+        }
+
+        /// <summary>
+        /// Gets the number of faces for the passed filter in the given media ID from the media database.
+        /// </summary>
+        /// <returns>
+        /// int count</returns>
+        /// <param name="filter">The Filter for matching Face</param>
+        public int GetMediaFaceCount(ContentFilter filter)
+        {
+            int count = 0;
+            IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
+            int result = Interop.MediaInformation.GetFaceCount(MediaId, handle, out count);
+            if ((MediaContentError)result != MediaContentError.None)
+            {
+                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
+            }
+            return count;
+        }
+
+
+        /// <summary>
+        /// Inserts a MediaFace item to the media database
+        /// </summary>
+        /// <param name="face">The MediaFace item to be inserted</param>
+        public MediaFace AddFace(ImageInformation image, FaceRect rect)
+        {
+            MediaFace face = new MediaFace(image, rect);
+            ContentManager.Database.Insert(face);
+            return face;
+        }
+
+        /// <summary>
+        /// Deletes a MediaFace from the media database.
+        /// For other types Unsupported exception is thrown.
+        /// </summary>
+        /// <param name="face">The face instance to be deleted</param>
+        public void DeleteFace(MediaFace face)
+        {
+            ContentManager.Database.Delete(face);
+        }
+
+        /// <summary>
+        /// Updates a media face instance in the media database
+        /// </summary>
+        /// <param name="mediaInfo">The MediaFace object to be updated</param>
+        public void UpdateFace(MediaFace face)
+        {
+            ContentManager.Database.Update(face);
+        }
+
         internal IntPtr ImageHandle
         {
             get
index 71bfd71..d0ab745 100644 (file)
@@ -24,10 +24,19 @@ namespace Tizen.Content.MediaContent
         private bool _disposedValue = false;
         internal readonly uint _offset;
         internal readonly String _thumbnailPath;
-        internal readonly String _mediaId;
         internal MediaBookmark(IntPtr handle)
         {
             _bookmarkHandle = handle;
+            MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetMarkedTime(_bookmarkHandle, out _offset);
+            if (res != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(res, "Failed to set Offset");
+            }
+            res = (MediaContentError)Interop.MediaBookmark.GetThumbnailPath(_bookmarkHandle, out _thumbnailPath);
+            if (res != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(res, "Failed to set Thumbnail Path");
+            }
         }
 
         ~MediaBookmark()
@@ -58,13 +67,7 @@ namespace Tizen.Content.MediaContent
         {
             get
             {
-                string path;
-                MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetThumbnailPath(_bookmarkHandle, out path);
-                if (res != MediaContentError.None)
-                {
-                    Log.Warn(Globals.LogTag, "Failed to get bookmark thumbnail path");
-                }
-                return path;
+                return _thumbnailPath;
             }
         }
 
@@ -75,20 +78,7 @@ namespace Tizen.Content.MediaContent
         {
             get
             {
-                uint time;
-                MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetMarkedTime(_bookmarkHandle, out time);
-                return time;
-            }
-        }
-
-        /// <summary>
-        /// The bookmark time offset (in milliseconds)
-        /// </summary>
-        internal string MediaId
-        {
-            get
-            {
-                return _mediaId;
+                return _offset;
             }
         }
 
@@ -99,10 +89,9 @@ namespace Tizen.Content.MediaContent
         /// <param name="thumbnailPath">The thumbnail path of video bookmark. If the media type is audio, then thumbnail is null.</param>
         public MediaBookmark(MediaInformation content, uint offset, string thumbnailPath)
         {
-            _mediaId = content.MediaId;
             _offset = offset;
-            if(thumbnailPath != null)
-            _thumbnailPath = thumbnailPath;
+            if (thumbnailPath != null)
+                _thumbnailPath = thumbnailPath;
         }
         public void Dispose()
         {
index f1009f8..eb2f00b 100755 (executable)
@@ -15,7 +15,7 @@ namespace Tizen.Content.MediaContent
             {
                 case MediaContentError.InavlidParameter:
                     {
-                        exp = new ArgumentException(msg +" Invalid Parameters Provided");
+                        exp = new ArgumentException(msg + " Invalid Parameters Provided");
                         break;
                     }
                 case MediaContentError.OutOfMemory:
index c91ebcd..7468d8f 100644 (file)
@@ -18,16 +18,16 @@ namespace Tizen.Content.MediaContent
     {
         private IntPtr _faceHandle;
         private bool _disposedValue = false;
-        internal IntPtr Handle\r
-        {\r
-            get\r
-            {\r
-                return _faceHandle;\r
-            }\r
-            set\r
-            {\r
-                _faceHandle = value;\r
-            }\r
+        internal IntPtr Handle
+        {
+            get
+            {
+                return _faceHandle;
+            }
+            set
+            {
+                _faceHandle = value;
+            }
         }
 
 
@@ -41,12 +41,17 @@ namespace Tizen.Content.MediaContent
         /// <param name="image">
         ///image item through which FaceRect has to be tagged.
         ///</param>
-        public MediaFace(MediaInformation image)
+        internal MediaFace(MediaInformation image, FaceRect rect)
         {
             MediaContentError res = (MediaContentError)Interop.Face.Create(image.MediaId, out _faceHandle);
             if (res != MediaContentError.None)
             {
-                Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                throw MediaContentErrorFactory.CreateException(res, "Failed to create MediaFace");
+            }
+            res = (MediaContentError)Interop.Face.SetFaceRect(_faceHandle, rect.X, rect.Y, rect.Width, rect.Height);
+            if (res != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(res, "Failed to set Rect to MediaFace");
             }
         }
 
@@ -69,7 +74,7 @@ namespace Tizen.Content.MediaContent
                 MediaContentError res = (MediaContentError)Interop.Face.GetFaceRect(_faceHandle, out x, out y, out width, out height);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Rect for the Face");
                 }
                 return new FaceRect(x, y, width, height);
             }
@@ -79,7 +84,7 @@ namespace Tizen.Content.MediaContent
                 MediaContentError res = (MediaContentError)Interop.Face.SetFaceRect(_faceHandle, rect.X, rect.Y, rect.Width, rect.Height);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to set Rect for the Face");
                 }
             }
         }
@@ -95,7 +100,7 @@ namespace Tizen.Content.MediaContent
                 MediaContentError res = (MediaContentError)Interop.Face.GetFaceId(_faceHandle, out id);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Id for the Face");
                 }
                 return id;
             }
@@ -112,7 +117,7 @@ namespace Tizen.Content.MediaContent
                 MediaContentError res = (MediaContentError)Interop.Face.GetMediaId(_faceHandle, out mediaId);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get media Id for the Face");
                 }
                 return mediaId;
             }
@@ -126,7 +131,7 @@ namespace Tizen.Content.MediaContent
                 MediaContentError res = (MediaContentError)Interop.Face.GetTag(_faceHandle, out tag);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Tag for the Face");
                 }
                 return tag;
             }
@@ -135,7 +140,7 @@ namespace Tizen.Content.MediaContent
                 MediaContentError res = (MediaContentError)Interop.Face.SetTag(_faceHandle, value);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Artist for the Album");
+                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to set Tag for the Face");
                 }
             }
         }
index 81a024b..67b846a 100644 (file)
@@ -211,7 +211,7 @@ namespace Tizen.Content.MediaContent
         {
             Dispose(false);
         }
-       public override void Dispose()
+        public override void Dispose()
         {
             Dispose(true);
             GC.SuppressFinalize(this);
@@ -244,22 +244,22 @@ namespace Tizen.Content.MediaContent
             List<MediaInformation> mediaContents = new List<MediaInformation>();
             IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
             MediaContentError res;
-            Interop.Folder.MediaInfoCallback callback = (Interop.MediaInformation.SafeMediaInformationHandle mediaHandle, IntPtr data) =>
+            Interop.Folder.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) =>
             {
-                //TODO: Create MediaInformation using safehandle.
                 Interop.MediaInformation.SafeMediaInformationHandle newHandle;
-                res = (MediaContentError)Interop.MediaInformation.Clone(out newHandle, mediaHandle.DangerousGetHandle());
+                res = (MediaContentError)Interop.MediaInformation.Clone(out newHandle, mediaHandle);
                 if (res != MediaContentError.None)
                 {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to clone media information");
+                    throw MediaContentErrorFactory.CreateException(res, "Failed to clone media information in folder");
                 }
                 MediaInformation info = new MediaInformation(newHandle);
                 mediaContents.Add(info);
+                return true;
             };
             res = (MediaContentError)Interop.Folder.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
             {
-                Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get media information for the folder");
+                throw MediaContentErrorFactory.CreateException(res, "Failed to get media information for the folder");
             }
             tcs.TrySetResult(mediaContents);
             return tcs.Task;
index fbb438c..251c056 100755 (executable)
@@ -15,6 +15,7 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 
 namespace Tizen.Content.MediaContent
@@ -48,42 +49,6 @@ namespace Tizen.Content.MediaContent
         }
 
         /// <summary>
-        /// Gets the number of bookmarks for the passed filter in the given media ID from the media database.
-        /// </summary>
-        /// <returns>
-        /// int count</returns>
-        /// <param name="filter">The Filter for matching BookMarks</param>
-        public int GetMediaBookMarkCount(ContentFilter filter)
-        {
-            int count = 0;
-            IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
-            MediaContentError result = (MediaContentError) Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count);
-            if (result != MediaContentError.None)
-            {
-                throw MediaContentErrorFactory.CreateException(result, "Error Occured with error code: ");
-            }
-            return count;
-        }
-
-        /// <summary>
-        /// Gets the number of faces for the passed filter in the given media ID from the media database.
-        /// </summary>
-        /// <returns>
-        /// int count</returns>
-        /// <param name="filter">The Filter for matching Face</param>
-        public int GetFaceCount(ContentFilter filter)
-        {
-            int count = 0;
-            IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
-            int result = Interop.MediaInformation.GetFaceCount(MediaId, handle, out count);
-            if ((MediaContentError)result != MediaContentError.None)
-            {
-                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
-            }
-            return count;
-        }
-
-        /// <summary>
         /// Moves the media info to the given destination path in the media database.
         /// </summary>
         /// <returns>
@@ -113,38 +78,72 @@ namespace Tizen.Content.MediaContent
         }
 
         /// <summary>
-        /// Cancels the creation of image's thumbnail for the given media.
+        /// Creates a thumbnail image for the given media, asynchronously
         /// </summary>
         /// <returns>
-        /// void </returns>
-        public void CancelThumbnail()
+        /// Task for creation of Thumbnail </returns>
+        public Task<string> CreateThumbnailAsync()
         {
-            int result = Interop.MediaInformation.CancelThumbnail(_handle);
+            var task = new TaskCompletionSource<string>();
+            Interop.MediaInformation.MediaThumbnailCompletedCallback thumbnailResult = (MediaContentError createResult, string path, IntPtr userData) =>
+            {
+                if (createResult == MediaContentError.None)
+                {
+                    task.SetResult(path);
+                }
+                else
+                {
+                    Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)createResult);
+                    task.SetException(MediaContentErrorFactory.CreateException((MediaContentError)createResult, "Failed to create Thumbnail"));
+                }
+            };
+            int result = Interop.MediaInformation.CreateThumbnail(_handle, thumbnailResult, IntPtr.Zero);
             if ((MediaContentError)result != MediaContentError.None)
             {
                 Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
             }
+            return task.Task;
         }
 
         /// <summary>
         /// Creates a thumbnail image for the given media, asynchronously
+        /// which can be cancelled
         /// </summary>
         /// <returns>
         /// Task for creation of Thumbnail </returns>
-        public Task<CreateThumbnailResult> CreateThumbnailAsync()
+        public Task<string> CreateThumbnailAsync(CancellationToken cancellationToken)
         {
-            var task = new TaskCompletionSource<CreateThumbnailResult>();
+            var task = new TaskCompletionSource<string>();
+            cancellationToken.Register(() => {
+                Log.Info(Globals.LogTag, "Cancel thumbnail Called");
+                int resultCancel = Interop.MediaInformation.CancelThumbnail(_handle);
+                if ((MediaContentError)resultCancel != MediaContentError.None)
+                {
+                    Log.Error(Globals.LogTag, "Cancel thumbnail failed with error code: " + (MediaContentError)resultCancel);
+                }
+                else
+                {
+                    task.SetCanceled();
+                }
+            });
             Interop.MediaInformation.MediaThumbnailCompletedCallback thumbnailResult = (MediaContentError createResult, string path, IntPtr userData) =>
             {
-                CreateThumbnailResult response = new CreateThumbnailResult();
-                response.Result = createResult;
-                response.FilePath = path;
-                task.SetResult(response);
+                Log.Info(Globals.LogTag, "Thumbnail Callabck Received");
+                if (createResult == MediaContentError.None)
+                {
+                    task.SetResult(path);
+                }
+                else
+                {
+                    Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)createResult);
+                    task.SetException(MediaContentErrorFactory.CreateException((MediaContentError)createResult, "Failed to create Thumbnail"));
+                }
             };
             int result = Interop.MediaInformation.CreateThumbnail(_handle, thumbnailResult, IntPtr.Zero);
             if ((MediaContentError)result != MediaContentError.None)
             {
                 Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
+                task.SetException(MediaContentErrorFactory.CreateException((MediaContentError)result, "Creating Thumbnail Fail"));
             }
             return task.Task;
         }
@@ -167,13 +166,13 @@ namespace Tizen.Content.MediaContent
                 result = (MediaContentError)Interop.Tag.Clone(out newHandle, tagHandle);
                 if (result != MediaContentError.None)
                 {
-                    Log.Error(Globals.LogTag, "Failed to clone Tag" );
+                    Log.Error(Globals.LogTag, "Failed to clone Tag");
                 }
                 Tag tag = new Tag(newHandle);
                 coll.Add(tag);
                 return true;
             };
-            result = (MediaContentError) Interop.MediaInformation.GetAllTags(MediaId, handle, tagsCallback, IntPtr.Zero);
+            result = (MediaContentError)Interop.MediaInformation.GetAllTags(MediaId, handle, tagsCallback, IntPtr.Zero);
             if (result != MediaContentError.None)
             {
                 Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
@@ -183,64 +182,6 @@ namespace Tizen.Content.MediaContent
         }
 
         /// <summary>
-        /// Iterates through the media bookmark in the given media info from the media database.
-        /// </summary>
-        /// <returns>
-        /// Task to get all the BookMarks </returns>
-        /// <param name="filter"> filter for the Tags</param>
-        public Task<IEnumerable<MediaBookmark>> GetMediaBookmarksAsync(ContentFilter filter)
-        {
-            var task = new TaskCompletionSource<IEnumerable<MediaBookmark>>();
-            MediaContentError result;
-            Collection<MediaBookmark> coll = new Collection<MediaBookmark>();
-            IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
-            Interop.MediaInformation.MediaBookMarkCallback bookmarksCallback = (IntPtr handle, IntPtr userData) =>
-            {
-                IntPtr newHandle;
-                result = (MediaContentError)Interop.MediaBookmark.Clone(out newHandle, handle);
-                if (result != MediaContentError.None)
-                {
-                    Log.Error(Globals.LogTag, "Failed to clone Tag");
-                }
-                MediaBookmark bookmark = new MediaBookmark(newHandle);
-                coll.Add(bookmark);
-                return true;
-            };
-            result = (MediaContentError) Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, bookmarksCallback, IntPtr.Zero);
-            if (result != MediaContentError.None)
-            {
-                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
-            }
-            task.SetResult(coll);
-            return task.Task;
-        }
-
-        /// <summary>
-        /// Iterates through the media files with optional media_id in the given face face from the media database.
-        /// </summary>
-        /// <returns>
-        /// Task to get all the MediaFaces </returns>
-        /// <param name="filter"> filter for the Tags</param>
-        public Task<IEnumerable<MediaFace>> GetMediaFacesAsync(ContentFilter filter)
-        {
-            var task = new TaskCompletionSource<IEnumerable<MediaFace>>();
-            Collection<MediaFace> coll = new Collection<MediaFace>();
-            Interop.MediaInformation.MediaFaceCallback faceCallback = (IntPtr facehandle, IntPtr userData) =>
-            {
-                MediaFace face = new MediaFace(facehandle);
-                coll.Add(face);
-                return true;
-            };
-            int result = Interop.MediaInformation.GetAllFaces(MediaId, filter.Handle, faceCallback, IntPtr.Zero);
-            if ((MediaContentError)result != MediaContentError.None)
-            {
-                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
-            }
-            task.SetResult(coll);
-            return task.Task;
-        }
-
-        /// <summary>
         ///  Gets the tag ID for the media.
         /// </summary>
         /// <value> string tag ID</value>
@@ -680,7 +621,7 @@ namespace Tizen.Content.MediaContent
                 int result = Interop.MediaInformation.SetAuthor(_handle, value);
                 if ((MediaContentError)result != MediaContentError.None)
                 {
-                    throw MediaContentErrorFactory.CreateException((MediaContentError)result,"failed to set author");
+                    throw MediaContentErrorFactory.CreateException((MediaContentError)result, "failed to set author");
                 }
             }
         }
index d4da91a..4748d24 100644 (file)
@@ -22,7 +22,7 @@ namespace Tizen.Content.MediaContent
     /// </remarks>
     public class PlayList : ContentCollection
     {
-        private IDictionary<string, int> dictionary = new Dictionary<string, int>();
+        private readonly IDictionary<string, int> _dictionary = new Dictionary<string, int>();
         private IntPtr _playlistHandle;
         internal IntPtr Handle
         {
@@ -38,7 +38,7 @@ namespace Tizen.Content.MediaContent
 
         private void refreshPlaylistDictionary()
         {
-            dictionary.Clear();
+            _dictionary.Clear();
             MediaContentError res;
             Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) =>
             {
@@ -52,7 +52,8 @@ namespace Tizen.Content.MediaContent
                 MediaInformation info = new MediaInformation(newHandle);
                 string mediaId;
                 Interop.MediaInformation.GetMediaId(newHandle, out mediaId);
-                dictionary.Add(mediaId, memberId);
+                _dictionary.Add(mediaId, memberId);
+                return true;
             };
             res = (MediaContentError)Interop.Playlist.ForeachMediaFromDb(Id, IntPtr.Zero, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
@@ -77,6 +78,8 @@ namespace Tizen.Content.MediaContent
                 return id;
             }
         }
+
+        internal string _playListName;
         /// <summary>
         /// The playlist name
         /// </summary>
@@ -84,18 +87,16 @@ namespace Tizen.Content.MediaContent
         {
             get
             {
-                string name;
-                MediaContentError res = (MediaContentError)Interop.Playlist.GetName(_playlistHandle, out name);
-                if (res != MediaContentError.None)
-                {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Name for the PlayList");
-                }
-                return name;
+                return _playListName;
             }
             set
             {
                 MediaContentError res = (MediaContentError)Interop.Playlist.SetName(_playlistHandle, value);
-                if (res != MediaContentError.None)
+                if (res == MediaContentError.None)
+                {
+                    _playListName = value;
+                }
+                else
                 {
                     Log.Warn(MediaContentErrorFactory.LogTag, "Failed to set Name for the PlayList");
                 }
@@ -132,18 +133,17 @@ namespace Tizen.Content.MediaContent
         /// <param name="name">The name of the inserted playlist</param>
         public PlayList(string name)
         {
-            Name = name;
-            ContentManager.Database.ConnectToDB();
-            MediaContentError res = (MediaContentError) Interop.Playlist.InsertToDb(name, out _playlistHandle);
-            if(res != MediaContentError.None)
-            {
-                throw MediaContentErrorFactory.CreateException(res, "Failed to create playlist");
-            }
+            _playListName = name;
         }
 
         internal PlayList(IntPtr handle)
         {
             _playlistHandle = handle;
+            MediaContentError res = (MediaContentError)Interop.Playlist.GetName(handle, out _playListName);
+            if (res != MediaContentError.None)
+            {
+                Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Name for the PlayList");
+            }
         }
 
         /// <summary>
@@ -166,12 +166,13 @@ namespace Tizen.Content.MediaContent
         /// <param name="mediaContent">The AudioContent object to be removed</param>
         public void RemoveItem(MediaInformation media)
         {
-            int memberId = -1;
-            dictionary.TryGetValue(media.MediaId, out memberId);
-            if (memberId == -1) {
+            int memberId = 0;
+            _dictionary.TryGetValue(media.MediaId, out memberId);
+            if (memberId == 0)
+            {
                 refreshPlaylistDictionary();
             }
-            dictionary.TryGetValue(media.MediaId, out memberId);
+            _dictionary.TryGetValue(media.MediaId, out memberId);
             MediaContentError res = (MediaContentError)Interop.Playlist.RemoveMedia(_playlistHandle, memberId);
             if (res != MediaContentError.None)
             {
@@ -182,10 +183,19 @@ namespace Tizen.Content.MediaContent
         /// <summary>
         /// Sets the playing order in the playlist.
         /// </summary>
-        /// <param name="playListMemberId">The playlist member ID</param>
+        /// <param name="media">The playlist reference</param>
         /// <param name="playOrder">The playing order</param>
-        public void SetPlayOrder(int memberId, int playOrder)
+        public void SetPlayOrder(MediaInformation media, int playOrder)
         {
+            Tizen.Log.Info("TCT", "Order set for Media Id: " + media.MediaId);
+            int memberId;
+            _dictionary.TryGetValue(media.MediaId, out memberId);
+            if (memberId == 0)
+            {
+                refreshPlaylistDictionary();
+                _dictionary.TryGetValue(media.MediaId, out memberId);
+            }
+            Tizen.Log.Info("TCT", "Order set for member Id: " + memberId);
             MediaContentError res = (MediaContentError)Interop.Playlist.SetPlayOrder(_playlistHandle, memberId, playOrder);
             if (res != MediaContentError.None)
             {
@@ -198,9 +208,18 @@ namespace Tizen.Content.MediaContent
         /// </summary>
         /// <param name="playListMemberId"></param>
         /// <param name="playOrder"></param>
-        public int GetPlayOrder(int memberId)
+        public int GetPlayOrder(MediaInformation media)
         {
+            Tizen.Log.Info("TCT", "Getting order for Media Id: " + media.MediaId);
             int playOrder;
+            int memberId;
+            _dictionary.TryGetValue(media.MediaId, out memberId);
+            if (memberId == 0)
+            {
+                refreshPlaylistDictionary();
+                _dictionary.TryGetValue(media.MediaId, out memberId);
+            }
+            Tizen.Log.Info("TCT", "Order set for Member Id: " + memberId);
             MediaContentError res = (MediaContentError)Interop.Playlist.GetPlayOrder(_playlistHandle, memberId, out playOrder);
             if (res != MediaContentError.None)
             {
@@ -236,7 +255,6 @@ namespace Tizen.Content.MediaContent
         /// <returns>path The path to export the playlist</returns>
         public static void Export(PlayList list, string filePath)
         {
-
             MediaContentError res = (MediaContentError)Interop.Playlist.ExportToFile(list.Handle, filePath);
             if (res != MediaContentError.None)
             {
@@ -293,6 +311,7 @@ namespace Tizen.Content.MediaContent
                 }
                 MediaInformation info = new MediaInformation(newHandle);
                 mediaContents.Add(info);
+                return true;
             };
             res = (MediaContentError)Interop.Playlist.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
index 21ab3d2..4ae5543 100644 (file)
@@ -140,16 +140,17 @@ namespace Tizen.Content.MediaContent
             List<MediaInformation> mediaContents = new List<MediaInformation>();
             MediaContentError res;
             IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
-            Interop.Storage.MediaInfoCallback callback = (Interop.MediaInformation.SafeMediaInformationHandle mediaHandle, IntPtr data) =>
+            Interop.Storage.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) =>
             {
                 Interop.MediaInformation.SafeMediaInformationHandle newHandle;
-                res = (MediaContentError)Interop.MediaInformation.Clone(out newHandle, mediaHandle.DangerousGetHandle());
+                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);
                 mediaContents.Add(info);
+                return true;
             };
             res = (MediaContentError)Interop.Storage.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero);
             if (res != MediaContentError.None)
index 53b0058..8ea4a4b 100644 (file)
@@ -20,6 +20,7 @@ namespace Tizen.Content.MediaContent
     public class Tag : ContentCollection
     {
         private IntPtr _tagHandle;
+        private string _tagName;
         internal IntPtr Handle
         {
             get
@@ -55,18 +56,16 @@ namespace Tizen.Content.MediaContent
         {
             get
             {
-                string name;
-                MediaContentError res = (MediaContentError)Interop.Tag.GetName(_tagHandle, out name);
-                if (res != MediaContentError.None)
-                {
-                    Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get Id for the Tag");
-                }
-                return name;
+                return _tagName;
             }
             set
             {
                 MediaContentError res = (MediaContentError)Interop.Tag.SetName(_tagHandle, value);
-                if (res != MediaContentError.None)
+                if (res == MediaContentError.None)
+                {
+                    _tagName = value;
+                }
+                else
                 {
                     Log.Warn(MediaContentErrorFactory.LogTag, "Failed to set name for the Tag");
                 }
@@ -76,6 +75,11 @@ namespace Tizen.Content.MediaContent
         internal Tag(IntPtr tagHandle)
         {
             _tagHandle = tagHandle;
+            MediaContentError error = (MediaContentError)Interop.Tag.GetName(tagHandle, out _tagName);
+            if (error != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(error, "Failed to get the tage Name");
+            }
         }
         /// <summary>
         /// Creates a Tag object which can be inserted to the media database using ContentManager:InsertToDatabaseAsync(ContentCollection)
@@ -83,17 +87,7 @@ namespace Tizen.Content.MediaContent
         /// <param name="tagName">The name of the media tag</param>
         public Tag(string tagName)
         {
-            Name = tagName;
-            ContentManager.Database.ConnectToDB();
-            MediaContentError res = (MediaContentError)Interop.Tag.InsertToDb(tagName, out _tagHandle);
-            if (res != MediaContentError.None)
-            {
-                Console.WriteLine("Exception occured "+ res);
-                throw MediaContentErrorFactory.CreateException(res, "Failed to create playlist");
-            }
-            string test;
-            Interop.Tag.GetName(_tagHandle, out test);
-            Console.WriteLine("test name " + res);
+            _tagName = tagName;
         }
 
         /// <summary>
index f828975..708131f 100644 (file)
@@ -15,6 +15,7 @@ using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading.Tasks;
+using System.Collections.ObjectModel;
 
 namespace Tizen.Content.MediaContent
 {
@@ -295,7 +296,7 @@ namespace Tizen.Content.MediaContent
                 int result = Interop.VideoInformation.SetPlayedCount(_handle, value);
                 if ((MediaContentError)result != MediaContentError.None)
                 {
-                    throw MediaContentErrorFactory.CreateException((MediaContentError)result,"Failed to set played count");
+                    throw MediaContentErrorFactory.CreateException((MediaContentError)result, "Failed to set played count");
                 }
             }
         }
@@ -335,7 +336,7 @@ namespace Tizen.Content.MediaContent
                 int result = Interop.VideoInformation.SetPlayedTime(_handle, (int)value.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds);
                 if ((MediaContentError)result != MediaContentError.None)
                 {
-                    throw MediaContentErrorFactory.CreateException((MediaContentError)result,"failed to set played time");
+                    throw MediaContentErrorFactory.CreateException((MediaContentError)result, "failed to set played time");
                 }
             }
         }
@@ -361,11 +362,97 @@ namespace Tizen.Content.MediaContent
                 int result = Interop.VideoInformation.SetPlayedPosition(_handle, value);
                 if ((MediaContentError)result != MediaContentError.None)
                 {
-                    throw MediaContentErrorFactory.CreateException((MediaContentError)result,"failed to set played position");
+                    throw MediaContentErrorFactory.CreateException((MediaContentError)result, "failed to set played position");
                 }
             }
         }
 
+        /// <summary>
+        /// Gets the number of bookmarks for the passed filter in the given media ID from the media database.
+        /// </summary>
+        /// <returns>
+        /// int count</returns>
+        /// <param name="filter">The Filter for matching BookMarks</param>
+        public int GetMediaBookMarkCount(ContentFilter filter)
+        {
+            int count = 0;
+            IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
+            MediaContentError result = (MediaContentError)Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count);
+            if (result != MediaContentError.None)
+            {
+                throw MediaContentErrorFactory.CreateException(result, "Error Occured with error code: ");
+            }
+            return count;
+        }
+
+        /// <summary>
+        /// Iterates through the media bookmark in the given media info from the media database.
+        /// </summary>
+        /// <returns>
+        /// Task to get all the BookMarks </returns>
+        /// <param name="filter"> filter for the Tags</param>
+        public Task<IEnumerable<MediaBookmark>> GetMediaBookmarksAsync(ContentFilter filter)
+        {
+            var task = new TaskCompletionSource<IEnumerable<MediaBookmark>>();
+            MediaContentError result;
+            Collection<MediaBookmark> coll = new Collection<MediaBookmark>();
+            IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
+            Interop.MediaInformation.MediaBookMarkCallback bookmarksCallback = (IntPtr handle, IntPtr userData) =>
+            {
+                IntPtr newHandle;
+                result = (MediaContentError)Interop.MediaBookmark.Clone(out newHandle, handle);
+                if (result != MediaContentError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to clone Tag");
+                }
+                MediaBookmark bookmark = new MediaBookmark(newHandle);
+                coll.Add(bookmark);
+                return true;
+            };
+            result = (MediaContentError)Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, bookmarksCallback, IntPtr.Zero);
+            if (result != MediaContentError.None)
+            {
+                Log.Error(Globals.LogTag, "Error Occured with error code: " + (MediaContentError)result);
+            }
+            task.SetResult(coll);
+            return task.Task;
+        }
+
+        /// <summary>
+        /// Adds a bookmark to the video
+        /// </summary>
+        /// <param name="offset">Offset of the video in seconds</param>
+        /// <param name="thumbnailPath">Thumbnail path for the bookmark</param>
+        /// <returns></returns>
+        public async Task<MediaBookmark> AddBookmark(uint offset, string thumbnailPath)
+        {
+            MediaBookmark result = null;
+            ContentManager.Database.Insert(MediaId, offset, thumbnailPath);
+            ContentFilter bookmarkfilter = new ContentFilter();
+            bookmarkfilter.Condition = "BOOKMARK_MARKED_TIME = " + offset;
+            IEnumerable<MediaBookmark> bookmarksList = null;
+            bookmarksList = await GetMediaBookmarksAsync(bookmarkfilter);
+            foreach (MediaBookmark bookmark in bookmarksList)
+            {
+                if (bookmark.Offset == offset)
+                {
+                    result = bookmark;
+                    break;
+                }
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// Deletes a bookmark from the media database.
+        /// For other types Unsupported exception is thrown.
+        /// </summary>
+        /// <param name="bookmark">The bookmark to be deleted</param>
+        public void DeleteBookmark(MediaBookmark bookmark)
+        {
+            ContentManager.Database.Delete(bookmark);
+        }
+
         internal IntPtr VideoHandle
         {
             get