Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / MediaBookmark.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19 using System;
20 using System.Runtime.InteropServices;
21
22 namespace Tizen.Content.MediaContent
23 {
24     /// <summary>
25     /// A MediaBookmark allows you to mark interesting moment in a media(video and audio) to enable fast searching.
26     /// The MediaBookmark Information API provides functions to get information about bookmarks associated with video and audio items.
27     /// </summary>
28     public class MediaBookmark : IDisposable
29     {
30         private IntPtr _bookmarkHandle = IntPtr.Zero;
31         private bool _disposedValue = false;
32
33         private IntPtr Handle
34         {
35             get
36             {
37                 if (_bookmarkHandle == IntPtr.Zero)
38                 {
39                     throw new ObjectDisposedException(nameof(MediaBookmark));
40                 }
41
42                 return _bookmarkHandle;
43             }
44         }
45         internal MediaBookmark(IntPtr handle)
46         {
47             _bookmarkHandle = handle;
48         }
49
50         ~MediaBookmark()
51         {
52             Dispose(false);
53         }
54         /// <summary>
55         /// The media bookmark ID
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         public int Id
59         {
60             get
61             {
62                 int id;
63                 MediaContentValidator.ThrowIfError(
64                     Interop.MediaBookmark.GetBookmarkId(Handle, out id), "Failed to get bookmark id");
65
66                 return id;
67             }
68         }
69
70         /// <summary>
71         /// The thumbnail path of media bookmark
72         /// </summary>
73         /// <since_tizen> 3 </since_tizen>
74         public string ThumbnailPath
75         {
76             get
77             {
78                 IntPtr val = IntPtr.Zero;
79                 try
80                 {
81                     MediaContentValidator.ThrowIfError(
82                         Interop.MediaBookmark.GetThumbnailPath(Handle, out val), "Failed to get bookmark thumbnail");
83
84                     return Marshal.PtrToStringAnsi(val);
85                 }
86                 finally
87                 {
88                     Interop.Libc.Free(val);
89                 }
90             }
91         }
92
93         /// <summary>
94         /// The bookmark time offset (in milliseconds)
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         public uint Offset
98         {
99             get
100             {
101                 uint offset;
102                 MediaContentValidator.ThrowIfError(
103                     Interop.MediaBookmark.GetMarkedTime(Handle, out offset), "Failed to get bookmarked time");
104
105                 return offset;
106             }
107         }
108
109         public void Dispose()
110         {
111             Dispose(true);
112             GC.SuppressFinalize(this);
113         }
114
115         protected virtual void Dispose(bool disposing)
116         {
117             if (!_disposedValue)
118             {
119                 if (_bookmarkHandle != IntPtr.Zero)
120                 {
121                     Interop.MediaBookmark.Destroy(_bookmarkHandle);
122                     _bookmarkHandle = IntPtr.Zero;
123                 }
124
125                 _disposedValue = true;
126             }
127         }
128     }
129 }