Name: csapi-media-content
Summary: Tizen Media Content API for C#
-Version: 1.0.8
+Version: 1.0.9
Release: 1
Group: Development/Libraries
License: Apache-2.0
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
internal static partial class Interop
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
-/*\r
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the License);\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an AS IS BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
public override void Dispose()
{
- if (_albumHandle != IntPtr.Zero) {
+ if (_albumHandle != IntPtr.Zero)
+ {
Interop.Group.MediaAlbumDestroy(_albumHandle);
_albumHandle = IntPtr.Zero;
}
break;
}
}
+
bookmarkfilter.Dispose();
return result;
}
internal ContentDatabase()
{
}
+
internal void ConnectToDB()
{
if (!_isConnected)
_isConnected = true;
}
}
+
private void DisconnectFromDB()
{
if (_isConnected)
string mimeType,
IntPtr userData) =>
{
- s_contentUpdated?.Invoke(
+ _contentUpdated?.Invoke(
null, new ContentUpdatedEventArgs(error, pid, updateItem, updateType, mediaType, uuid, filePath, mimeType));
};
- private static event EventHandler<ContentUpdatedEventArgs> s_contentUpdated;
+ private static event EventHandler<ContentUpdatedEventArgs> _contentUpdated;
/// <summary>
/// ContentUpdated event is triggered when the media DB changes.
/// </summary>
{
add
{
- if (s_contentUpdated == null)
+ if (_contentUpdated == null)
{
MediaContentValidator.ThrowIfError(
Interop.Content.SetDbUpdatedCb(s_contentUpdatedCallback, IntPtr.Zero), "Failed to set callback");
}
- s_contentUpdated += value;
+
+ _contentUpdated += value;
}
remove
{
- s_contentUpdated -= value;
- if (s_contentUpdated == null)
+ _contentUpdated -= value;
+ if (_contentUpdated == null)
{
MediaContentValidator.ThrowIfError(
Interop.Content.UnsetDbUpdatedCb(), "Failed to unset callback");
return (T)result;
}
+
return null;
}
/// This function gets all ContentCollections matching the given filter. If NULL is passed to the filter, no filtering is applied.
/// </remarks>
/// <param name="filter">Filter for content items</param>
- /// <returns></returns>
+ /// <returns>
+ /// Task with the list of the ContentCollection
+ /// </returns>
public Task<IEnumerable<T>> SelectAsync<T>(ContentFilter filter)
{
ConnectToDB();
IEnumerable<PlayList> collectionList = ForEachPlayList(filter);
task.TrySetResult((IEnumerable<T>)collectionList);
}
+
return task.Task;
}
return offset;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Filter.SetOffset(_filterHandle, value, this.Count), "Failed to set offset");
}
}
+
public ContentFilter()
{
MediaContentValidator.ThrowIfError(
Interop.Filter.Create(out _filterHandle), "Failed to Create Filter handle.");
}
+
/// <summary>
/// The number of items to be searched with respect to the offset
/// </summary>
return count;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Filter.SetOffset(_filterHandle, this.Offset, value), "Failed to set count");
}
}
+
/// <summary>
/// Gets the media filter content order and order keyword.
/// </summary>
}
}
}
+
/// <summary>
/// The collate type for comparing two strings
/// </summary>
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Filter.SetCondition(_filterHandle, this.Condition, value), "Failed to set collation");
}
}
+
/// <summary>
/// Gets/Sets the condition for the given filter.
/// </summary>
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Filter.SetCondition(_filterHandle, value, this.CollationType), "Failed to set condition");
}
}
+
/// <summary>
/// Sets the storage id for the given filter.
/// You can use this property when you want to search items only in the specific storage
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Filter.SetStorage(_filterHandle, value), "Failed to set condition");
}
}
+
/// <summary>
/// The search order keyword
/// </summary>
/// <summary>
/// SetOrderProperties like OrderType and OrderKey.
/// </summary>
+ /// <param name="order">ordering type</param>
+ /// <param name="oderKey">Keywords to sort</param>
public void SetOrderProperties(ContentOrder order, string oderKey)
{
MediaContentValidator.ThrowIfError(
Interop.Filter.Destroy(_filterHandle);
_filterHandle = IntPtr.Zero;
}
+
_disposedValue = true;
}
}
/// Inserts a media to the media database
/// </summary>
/// <param name="filePath">File path of the media to be inserted</param>
+ /// <returns>the MediaInformation instance about added media path</returns>
public static MediaInformation AddMediaInformation(string filePath)
{
Database.ConnectToDB();
/// 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>
+ /// <returns>Task with scanning result</returns>
public static Task ScanFolderAsync(string folderPath, bool recursive = true)
{
var task = new TaskCompletionSource<int>();
/// 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>
+ /// <returns>Task with scanning result</returns>
public static Task ScanFolderAsync(string folderPath, CancellationToken cancellationToken, bool recursive = true)
{
var task = new TaskCompletionSource<int>();
/// Inserts media files into the media database, asynchronously.
/// </summary>
/// <param name="filePaths">The path array to the media files</param>
- /// <returns></returns>
+ /// <returns>
+ /// Task with the result of batch insertion
+ /// </returns>
public static Task AddMediaInformationBatchAsync(IEnumerable<string> filePaths)
{
Database.ConnectToDB();
/// Inserts the burst shot images into the media database, asynchronously.
/// </summary>
/// <param name="filePaths">The path array to the burst shot images</param>
- /// <returns></returns>
+ /// <returns>
+ /// Task with the result of the burstshot insertion
+ /// </returns>
public static Task AddBurstShotImagesAsync(IEnumerable<string> filePaths)
{
Database.ConnectToDB();
/// without calling this function.This function is only called when the media server is busy and user needs to get quick result of deleting.
/// </summary>
/// <param name="filter">The content filter to which media will be matched</param>
- /// <returns></returns>
+ /// <returns>Task with the removal result </returns>
public static Task RemoveMediaInformationBatchAsync(ContentFilter filter)
{
Database.ConnectToDB();
return orientation;
}
+
set
{
MediaContentValidator.ThrowIfError(
/// </summary>
/// <param name="image">The image on which face is to be added</param>
/// <param name="rect">The dimensions of the face</param>
+ /// <returns>The MediaFace instance</returns>
public MediaFace AddFace(ImageInformation image, FaceRect rect)
{
MediaFace face = new MediaFace(image, rect);
{
_offset = offset;
if (thumbnailPath != null)
+ {
_thumbnailPath = thumbnailPath;
+ }
}
+
public void Dispose()
{
Dispose(true);
Interop.Face.Destroy(_bookmarkHandle);
_bookmarkHandle = IntPtr.Zero;
}
+
_disposedValue = true;
}
}
UnsupportedContent = TizenMediaContentError | 0x04,
NotSupported = ErrorCode.NotSupported,
}
+
internal class MediaContentValidator
{
internal const string LogTag = "Tizen.Content.MediaContent";
{
return _faceHandle;
}
+
set
{
_faceHandle = value;
{
_faceHandle = handle;
}
+
/// <summary>
/// Create Face for Given Image
/// </summary>
/// <param name="image">
///image item through which FaceRect has to be tagged.
///</param>
+ ///<param name="rect">Position about the detacted face in the media</param>
internal MediaFace(MediaInformation image, FaceRect rect)
{
MediaContentValidator.ThrowIfError(
return new FaceRect(x, y, width, height);
}
+
set
{
FaceRect rect = (FaceRect)value;
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
return (MediaContentOrientation)orientation;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Face.Destroy(_faceHandle);
_faceHandle = IntPtr.Zero;
}
+
_disposedValue = true;
}
}
{
return _folderHandle;
}
+
set
{
_folderHandle = value;
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
return order;
}
+
set
{
MediaContentValidator.ThrowIfError(
{
Dispose(false);
}
+
public override void Dispose()
{
Dispose(true);
{
if (_folderHandle != IntPtr.Zero)
{
- Console.WriteLine("Before destroy");
Interop.Folder.Destroy(_folderHandle);
_folderHandle = IntPtr.Zero;
- Console.WriteLine("After destroy");
}
+
_disposedValue = true;
}
}
+
/// <summary>
/// Iterates through the media files with an filter in the given folder from the media database.
/// This function gets all media files associated with the given folder and meeting desired filter option.
/// which can be cancelled
/// If a thumbnail already exists for the given media, then the path of thumbnail will be returned.
/// </summary>
+ /// <param name="cancellationToken">Token to cancel the requested operation</param>
/// <returns>
- /// Task for creation of Thumbnail </returns>
+ /// Task for creation of Thumbnail
+ /// </returns>
public async Task<string> CreateThumbnailAsync(CancellationToken cancellationToken)
{
var task = new TaskCompletionSource<string>();
- cancellationToken.Register(() => {
+ cancellationToken.Register(() =>
+ {
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.CancelThumbnail(_handle), "Failed to cancel");
+
task.SetCanceled();
});
+
Interop.MediaInformation.MediaThumbnailCompletedCallback thumbnailResult = (MediaContentError createResult, string path, IntPtr userData) =>
{
MediaContentValidator.ThrowIfError(createResult, "Failed to create thumbnail");
task.SetResult(path);
};
+
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.CreateThumbnail(_handle, thumbnailResult, IntPtr.Zero), "Failed to create thumbnail");
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
return utc.ToLocalTime();
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
return longitude;
}
+
set
{
MediaContentValidator.ThrowIfError(
return latitude;
}
+
set
{
MediaContentValidator.ThrowIfError(
return altitude;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.MediaInformation.GetRating(_handle, out rating), "Failed to get value");
return rating;
}
+
set
{
MediaContentValidator.ThrowIfError(
return isFavourtite;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
return playedCount;
}
+
set
{
MediaContentValidator.ThrowIfError(
return utc.ToLocalTime();
}
+
set
{
MediaContentValidator.ThrowIfError(
{
return _playlistHandle;
}
+
set
{
_playlistHandle = value;
}
}
- private void refreshPlaylistDictionary()
+ private void RefreshPlaylistDictionary()
{
_dictionary.Clear();
Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) =>
{
return _playListName;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
set
{
MediaContentValidator.ThrowIfError(
public void RemoveItem(MediaInformation media)
{
int memberId = 0;
- refreshPlaylistDictionary();
+ RefreshPlaylistDictionary();
_dictionary.TryGetValue(media.MediaId, out memberId);
MediaContentValidator.ThrowIfError(
Interop.Playlist.RemoveMedia(_playlistHandle, memberId), "Failed to remove item");
public void SetPlayOrder(MediaInformation media, int playOrder)
{
int memberId;
- refreshPlaylistDictionary();
+ RefreshPlaylistDictionary();
_dictionary.TryGetValue(media.MediaId, out memberId);
MediaContentValidator.ThrowIfError(
Interop.Playlist.SetPlayOrder(_playlistHandle, memberId, playOrder), "Failed to set play order");
/// <summary>
/// Gets the playing order in the playlist for the passed member id.
/// </summary>
- /// <param name="media"></param>
+ /// <param name="media">The MediaInformation instance</param>
+ /// <returns>The number of play order</returns>
public int GetPlayOrder(MediaInformation media)
{
int playOrder;
int memberId;
- refreshPlaylistDictionary();
+ RefreshPlaylistDictionary();
_dictionary.TryGetValue(media.MediaId, out memberId);
MediaContentValidator.ThrowIfError(
Interop.Playlist.GetPlayOrder(_playlistHandle, memberId, out playOrder), "Failed to get play order");
/// <summary>
/// Exports the playlist to m3u playlist file.
/// </summary>
+ /// <param name="list">The playlist instance to export</param>
+ /// <param name="filePath">The path to save exported playlist</param>
/// <returns>path The path to export the playlist</returns>
public static void Export(PlayList list, string filePath)
{
public override void Dispose()
{
- if (_playlistHandle != IntPtr.Zero) {
+ if (_playlistHandle != IntPtr.Zero)
+ {
Interop.Playlist.Destroy(_playlistHandle);
_playlistHandle = IntPtr.Zero;
}
{
return _tagHandle;
}
+
set
{
_tagHandle = value;
{
return _tagName;
}
+
set
{
MediaContentValidator.ThrowIfError(
Interop.Libc.Free(val);
}
}
+
/// <summary>
/// Creates a Tag object which can be inserted to the media database using ContentManager:InsertToDatabaseAsync(ContentCollection)
/// </summary>
mediaContents.Add(new MediaInformation(newHandle));
return true;
};
+
MediaContentValidator.ThrowIfError(
Interop.Tag.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get information");
tcs.TrySetResult(mediaContents);
+
return tcs.Task;
}
}
/// </summary>
/// <param name="offset">Offset of the video in seconds</param>
/// <param name="thumbnailPath">Thumbnail path for the bookmark</param>
- /// <returns></returns>
+ /// <returns>Task with added MediaBookmark instance </returns>
public async Task<MediaBookmark> AddBookmark(uint offset, string thumbnailPath)
{
MediaBookmark result = null;
break;
}
}
+
bookmarkfilter.Dispose();
return result;
}