[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);
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);
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);
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)
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
+using System.Collections.ObjectModel;
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
/// 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
/// from the media content service.
/// </remarks>
+
namespace Tizen.Content.MediaContent
{
/// <summary>
/// </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;
}
}
/// <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;
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;
}
{
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);
{
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);
}
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;
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;
{
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);
}
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();
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);
{
return _filterHandle;
}
-
}
/// <summary>
/// The start position of the given filter Starting from zero.
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>
/// </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
}
/// <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>
/// 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>
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;
}
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;
}
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;
}
}
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Collections.ObjectModel;
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
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()
{
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;
}
}
{
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;
}
}
/// <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()
{
{
case MediaContentError.InavlidParameter:
{
- exp = new ArgumentException(msg +" Invalid Parameters Provided");
+ exp = new ArgumentException(msg + " Invalid Parameters Provided");
break;
}
case MediaContentError.OutOfMemory:
{
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;
+ }
}
/// <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");
}
}
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);
}
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");
}
}
}
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;
}
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;
}
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;
}
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");
}
}
}
{
Dispose(false);
}
- public override void Dispose()
+ public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
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;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
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>
}
/// <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;
}
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);
}
/// <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>
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");
}
}
}
/// </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
{
private void refreshPlaylistDictionary()
{
- dictionary.Clear();
+ _dictionary.Clear();
MediaContentError res;
Interop.Playlist.PlaylistMemberCallback callback = (int memberId, IntPtr mediaHandle, IntPtr data) =>
{
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)
return id;
}
}
+
+ internal string _playListName;
/// <summary>
/// The playlist name
/// </summary>
{
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");
}
/// <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>
/// <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)
{
/// <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)
{
/// </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)
{
/// <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)
{
}
MediaInformation info = new MediaInformation(newHandle);
mediaContents.Add(info);
+ return true;
};
res = (MediaContentError)Interop.Playlist.ForeachMediaFromDb(Id, handle, callback, IntPtr.Zero);
if (res != MediaContentError.None)
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)
public class Tag : ContentCollection
{
private IntPtr _tagHandle;
+ private string _tagName;
internal IntPtr Handle
{
get
{
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");
}
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)
/// <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>
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
+using System.Collections.ObjectModel;
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");
}
}
}
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");
}
}
}
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