Fixed review comments and updated CSProj file.
[platform/core/csapi/media-content.git] / Tizen.Content / Tizen.Content.MediaContent / MediaBookmark.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc.("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9
10 using System;
11 using System.Collections.Generic;
12 using System.Linq;
13 using System.Text;
14
15 namespace Tizen.Content.MediaContent
16 {
17     /// <summary>
18     /// A MediaBookmark allows you to mark interesting moment in a media(video and audio) to enable fast searching.
19     /// The MediaBookmark Information API provides functions to get information about bookmarks associated with video and audio items.
20     /// </summary>
21     public class MediaBookmark : IDisposable
22     {
23         private IntPtr _bookmarkHandle;
24         private bool _disposedValue = false;
25         internal readonly DateTime _timeStamp;
26         internal readonly String _thumbnailPath;
27         internal readonly String _mediaId;
28         internal MediaBookmark(IntPtr handle)
29         {
30             _bookmarkHandle = handle;
31         }
32
33         ~MediaBookmark()
34         {
35             Dispose(false);
36         }
37         /// <summary>
38         /// The media bookmark ID
39         /// </summary>
40         public int Id
41         {
42             get
43             {
44                 int id;
45                 MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetBookmarkId(_bookmarkHandle, out id);
46                 if (res != MediaContentError.None)
47                 {
48                     Log.Warn(Globals.LogTag, "Failed to get bookmark id");
49                 }
50                 return id;
51             }
52         }
53
54         /// <summary>
55         /// The thumbnail path of media bookmark
56         /// </summary>
57         public string ThumbnailPath
58         {
59             get
60             {
61                 string path;
62                 MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetThumbnailPath(_bookmarkHandle, out path);
63                 if (res != MediaContentError.None)
64                 {
65                     Log.Warn(Globals.LogTag, "Failed to get bookmark thumbnail path");
66                 }
67                 return path;
68             }
69         }
70
71         /// <summary>
72         /// The bookmark time offset (in milliseconds)
73         /// </summary>
74         public uint TimeStamp
75         {
76             get
77             {
78                 uint time;
79                 MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetMarkedTime(_bookmarkHandle, out time);
80                 if (res != MediaContentError.None)
81                 {
82                     Log.Warn(Globals.LogTag, "Failed to get marked time for the bookmark");
83                 }
84                 return time;
85             }
86         }
87
88         /// <summary>
89         /// Inserts a new bookmark in media on the specified time offset to the media database.
90         /// </summary>
91         /// <param name="timeStamp">The bookmark time offset (in seconds)</param>
92         /// <param name="thumbnailPath">The thumbnail path of video bookmark. If the media type is audio, then thumbnail is null.</param>
93         public MediaBookmark(MediaInformation content, DateTime time, string thumbnailPath)
94         {
95             _mediaId = content.MediaId;
96             _timeStamp = time;
97             if(thumbnailPath != null)
98             _thumbnailPath = thumbnailPath;
99         }
100         public void Dispose()
101         {
102             Dispose(true);
103             GC.SuppressFinalize(this);
104         }
105
106         protected virtual void Dispose(bool disposing)
107         {
108             if (!_disposedValue)
109             {
110                 if (_bookmarkHandle != IntPtr.Zero)
111                 {
112                     Interop.Face.Destroy(_bookmarkHandle);
113                     _bookmarkHandle = IntPtr.Zero;
114                 }
115                 _disposedValue = true;
116             }
117         }
118     }
119 }