2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using System.Collections.Generic;
21 using System.Runtime.InteropServices;
22 using System.Threading.Tasks;
23 using System.Collections.ObjectModel;
25 namespace Tizen.Content.MediaContent
28 /// VideoContent class API gives the information related to the image media stored in the device
30 public class VideoInformation : MediaInformation
33 /// Gets the ID of the media.
35 /// <since_tizen> 3 </since_tizen>
40 IntPtr val = IntPtr.Zero;
43 MediaContentValidator.ThrowIfError(
44 Interop.VideoInformation.GetMediaId(_handle, out val), "Failed to get value");
46 return Marshal.PtrToStringAnsi(val);
50 Interop.Libc.Free(val);
56 /// Gets the album name.
57 /// If the media content has no album information, the property returns empty string.
59 /// <since_tizen> 3 </since_tizen>
64 IntPtr val = IntPtr.Zero;
67 MediaContentValidator.ThrowIfError(
68 Interop.VideoInformation.GetAlbum(_handle, out val), "Failed to get value");
70 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
74 Interop.Libc.Free(val);
80 /// Gets the artist name.
81 /// If the media content has no artist information, the property returns empty string.
83 /// <since_tizen> 3 </since_tizen>
88 IntPtr val = IntPtr.Zero;
91 MediaContentValidator.ThrowIfError(
92 Interop.VideoInformation.GetArtist(_handle, out val), "Failed to get value");
94 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
98 Interop.Libc.Free(val);
104 /// Gets the album artist name.
105 /// If the media content has no album artist information, the property returns empty string.
107 /// <since_tizen> 3 </since_tizen>
108 public string AlbumArtist
112 IntPtr val = IntPtr.Zero;
115 MediaContentValidator.ThrowIfError(
116 Interop.VideoInformation.GetAlbumArtist(_handle, out val), "Failed to get value");
118 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
122 Interop.Libc.Free(val);
128 /// Gets the genre name.
129 /// If the media content has no genre information, the property returns empty string.
131 /// <since_tizen> 3 </since_tizen>
136 IntPtr val = IntPtr.Zero;
139 MediaContentValidator.ThrowIfError(
140 Interop.VideoInformation.GetGenre(_handle, out val), "Failed to get value");
142 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
146 Interop.Libc.Free(val);
152 /// Gets the composer name.
153 /// If the media content has no composer information, the property returns empty string.
155 /// <since_tizen> 3 </since_tizen>
156 public string Composer
160 IntPtr val = IntPtr.Zero;
163 MediaContentValidator.ThrowIfError(
164 Interop.VideoInformation.GetComposer(_handle, out val), "Failed to get value");
166 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
170 Interop.Libc.Free(val);
177 /// If the media content has no year information, the property returns empty string.
179 /// <since_tizen> 3 </since_tizen>
184 IntPtr val = IntPtr.Zero;
187 MediaContentValidator.ThrowIfError(
188 Interop.VideoInformation.GetYear(_handle, out val), "Failed to get value");
190 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
194 Interop.Libc.Free(val);
200 /// Gets the recorded date.
202 /// <since_tizen> 3 </since_tizen>
203 public string RecordedDate
207 IntPtr val = IntPtr.Zero;
210 MediaContentValidator.ThrowIfError(
211 Interop.VideoInformation.GetRecordedDate(_handle, out val), "Failed to get value");
213 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
217 Interop.Libc.Free(val);
223 /// Gets the copyright notice.
224 /// If the media content has no copyright information, the property returns empty string.
226 /// <since_tizen> 3 </since_tizen>
227 public string Copyright
231 IntPtr val = IntPtr.Zero;
234 MediaContentValidator.ThrowIfError(
235 Interop.VideoInformation.GetCopyright(_handle, out val), "Failed to get value");
237 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
241 Interop.Libc.Free(val);
247 /// Gets the track number.
248 /// If the media content has no track information, the property returns empty string.
250 /// <since_tizen> 3 </since_tizen>
251 public string TrackNumber
255 IntPtr val = IntPtr.Zero;
258 MediaContentValidator.ThrowIfError(
259 Interop.VideoInformation.GetTrackNum(_handle, out val), "Failed to get value");
261 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
265 Interop.Libc.Free(val);
271 /// Gets the bitrate in bit per second [bps].
273 /// <since_tizen> 3 </since_tizen>
279 MediaContentValidator.ThrowIfError(
280 Interop.VideoInformation.GetBitRate(_handle, out bitrate), "Failed to get value");
287 /// Gets the track duration in Milliseconds.
289 /// <since_tizen> 3 </since_tizen>
295 MediaContentValidator.ThrowIfError(
296 Interop.VideoInformation.GetDuration(_handle, out duration), "Failed to get value");
303 /// Gets the video width in pixels.
305 /// <since_tizen> 3 </since_tizen>
311 MediaContentValidator.ThrowIfError(
312 Interop.VideoInformation.GetWidth(_handle, out width), "Failed to get value");
319 /// Gets the video height in pixels.
321 /// <since_tizen> 3 </since_tizen>
327 MediaContentValidator.ThrowIfError(
328 Interop.VideoInformation.GetHeight(_handle, out height), "Failed to get value");
335 /// Gets the number of bookmarks for the passed filter in the given media ID from the media database.
337 /// <since_tizen> 3 </since_tizen>
339 /// int count</returns>
340 /// <param name="filter">The Filter for matching Bookmarks</param>
341 public int GetMediaBookmarkCount(ContentFilter filter)
344 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
345 MediaContentValidator.ThrowIfError(
346 Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count), "Failed to get count");
352 /// Iterates through the media bookmark in the given media info from the media database.
354 /// <since_tizen> 3 </since_tizen>
356 /// Task to get all the Bookmarks </returns>
357 /// <param name="filter"> filter for the Tags</param>
358 public IEnumerable<MediaBookmark> GetMediaBookmarks(ContentFilter filter)
360 Collection<MediaBookmark> result = new Collection<MediaBookmark>();
361 IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
362 Interop.MediaInformation.MediaBookmarkCallback callback = (IntPtr handle, IntPtr userData) =>
364 IntPtr newHandle = IntPtr.Zero;
365 MediaContentValidator.ThrowIfError(
366 Interop.MediaBookmark.Clone(out newHandle, handle), "Failed to clone Tag");
367 result.Add(new MediaBookmark(newHandle));
370 MediaContentValidator.ThrowIfError(
371 Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value");
377 /// Adds a bookmark to the video
379 /// <since_tizen> 3 </since_tizen>
380 /// <param name="offset">Offset of the video in seconds</param>
381 /// <param name="thumbnailPath">Thumbnail path for the bookmark</param>
382 /// <returns>Task with added MediaBookmark instance </returns>
383 public MediaBookmark AddBookmark(uint offset, string thumbnailPath)
385 MediaBookmark result = null;
386 ContentManager.Database.Insert(MediaId, offset, thumbnailPath);
387 ContentFilter bookmarkfilter = new ContentFilter();
388 bookmarkfilter.Condition = ContentColumns.Bookmark.Offset + " = " + offset;
389 IEnumerable<MediaBookmark> bookmarksList = null;
390 bookmarksList = GetMediaBookmarks(bookmarkfilter);
391 foreach (MediaBookmark bookmark in bookmarksList)
393 if (bookmark.Offset == offset)
400 bookmarkfilter.Dispose();
405 /// Deletes a bookmark from the media database.
406 /// For other types Unsupported exception is thrown.
408 /// <since_tizen> 3 </since_tizen>
409 /// <param name="bookmark">The bookmark to be deleted</param>
410 public void DeleteBookmark(MediaBookmark bookmark)
412 ContentManager.Database.Delete(bookmark);
415 internal IntPtr VideoHandle
419 return _handle.DangerousGetHandle();
423 private readonly Interop.VideoInformation.SafeVideoInformationHandle _handle;
425 internal VideoInformation(Interop.VideoInformation.SafeVideoInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle)
426 : base(mediaInformationHandle)