[MediaContent] Add CreateThumbnail and deprecate CreateThumbnailAsync (#4534)
authorHaesu Gwon <haesu.gwon@samsung.com>
Wed, 7 Sep 2022 07:34:00 +0000 (16:34 +0900)
committerGitHub <noreply@github.com>
Wed, 7 Sep 2022 07:34:00 +0000 (16:34 +0900)
* [MediaContent] Add CreateThumbnail and deprecate CreateThumbnailAsync

src/Tizen.Content.MediaContent/Interop/Interop.MediaInfo.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs

index 0822c4d..baa7e33 100644 (file)
@@ -156,13 +156,6 @@ internal static partial class Interop
         [DllImport(Libraries.MediaContent, EntryPoint = "media_info_move_to_db")]
         internal static extern MediaContentError MoveToDB(MediaInfoHandle mediaInformationHandle, string dstPath);
 
-        [DllImport(Libraries.MediaContent, EntryPoint = "media_info_create_thumbnail")]
-        internal static extern MediaContentError CreateThumbnail(MediaInfoHandle handle,
-            ThumbnailCompletedCallback callback, IntPtr userData = default(IntPtr));
-
-        [DllImport(Libraries.MediaContent, EntryPoint = "media_info_cancel_thumbnail")]
-        internal static extern MediaContentError CancelThumbnail(MediaInfoHandle mediaInformationHandle);
-
         [DllImport(Libraries.MediaContent, EntryPoint = "media_info_generate_thumbnail")]
         internal static extern MediaContentError GenerateThumbnail(MediaInfoHandle handle);
 
index e2f51ba..1b2e53e 100644 (file)
@@ -875,6 +875,7 @@ namespace Tizen.Content.MediaContent
         ///     The media is in the external USB storage (<see cref="MediaInfo.StorageType"/> is <see cref="StorageType.ExternalUsb"/>).
         /// </exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API10; Will be removed in API12. Please use CreateThumbnail instead.")]
         public Task<string> CreateThumbnailAsync(string mediaId)
         {
             return CreateThumbnailAsync(mediaId, CancellationToken.None);
@@ -907,6 +908,7 @@ namespace Tizen.Content.MediaContent
         ///     The media is in the external USB storage (<see cref="MediaInfo.StorageType"/> is <see cref="StorageType.ExternalUsb"/>).
         /// </exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API10; Will be removed in API12. Please use CreateThumbnail instead.")]
         public Task<string> CreateThumbnailAsync(string mediaId, CancellationToken cancellationToken)
         {
             ValidateDatabase();
@@ -962,6 +964,49 @@ namespace Tizen.Content.MediaContent
         }
         #endregion
 
+        /// <summary>
+        /// Creates the thumbnail image for the given media.
+        /// If the thumbnail already exists for the given media, the existing path will be returned.
+        /// </summary>
+        /// <privilege>http://tizen.org/privilege/content.write</privilege>
+        /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+        /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+        /// <param name="mediaId">The ID of the media for which the thumbnail will be created.</param>
+        /// <returns>A created thumbnail path.</returns>
+        /// <exception cref="InvalidOperationException">
+        ///     The <see cref="MediaDatabase"/> is disconnected.<br/>
+        ///     -or-<br/>
+        ///     An internal error occurred while executing.
+        /// </exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
+        /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
+        /// <exception cref="RecordNotFoundException"><paramref name="mediaId"/> does not exist in the database.</exception>
+        /// <exception cref="ArgumentException">
+        ///     <paramref name="mediaId"/> is a zero-length string, contains only white space.
+        /// </exception>
+        /// <exception cref="FileNotFoundException">The file of the media does not exists; moved or deleted.</exception>
+        /// <exception cref="UnsupportedContentException">
+        ///     The thumbnail is not available for the given media.<br/>
+        ///     -or-<br/>
+        ///     The media is in the external USB storage (<see cref="MediaInfo.StorageType"/> is <see cref="StorageType.ExternalUsb"/>).
+        /// </exception>
+        /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        public string CreateThumbnail(string mediaId)
+        {
+            ValidateDatabase();
+
+            ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId));
+
+            using (var handle = ValidateFile(mediaId))
+            {
+                Interop.MediaInfo.GenerateThumbnail(handle).ThrowIfError("Failed to create thumbnail");
+
+                return InteropHelper.GetString(handle, Interop.MediaInfo.GetThumbnailPath, true);
+            }
+        }
+
         private Interop.MediaInfoHandle ValidateFile(string mediaId)
         {
             Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle).ThrowIfError("Failed to create thumbnail");