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 /// AudioContent class API gives the information related to the audio media stored in the device
29 /// Its purpose is threefold:
30 /// - to provide information about audio content
31 /// - to organize audio content logically(grouping)
33 public class AudioInformation : MediaInformation
35 private readonly Interop.AudioInformation.SafeAudioInformationHandle _handle;
38 /// Gets the ID of the media.
40 /// <since_tizen> 3 </since_tizen>
45 IntPtr val = IntPtr.Zero;
48 MediaContentValidator.ThrowIfError(
49 Interop.AudioInformation.GetMediaId(_handle, out val), "Failed to get value");
51 return Marshal.PtrToStringAnsi(val);
55 Interop.Libc.Free(val);
61 /// Gets the album name.
62 /// If the media content has no album info, the property returns empty string.
64 /// <since_tizen> 3 </since_tizen>
69 IntPtr val = IntPtr.Zero;
72 MediaContentValidator.ThrowIfError(
73 Interop.AudioInformation.GetAlbum(_handle, out val), "Failed to get value");
75 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
79 Interop.Libc.Free(val);
85 /// Gets the artist name.
86 /// If the media content has no album info, the property returns empty string.
88 /// <since_tizen> 3 </since_tizen>
93 IntPtr val = IntPtr.Zero;
96 MediaContentValidator.ThrowIfError(
97 Interop.AudioInformation.GetArtist(_handle, out val), "Failed to get value");
99 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
103 Interop.Libc.Free(val);
109 /// Gets the album artist name.
110 /// If the media content has no album info, the property returns empty string.
112 /// <since_tizen> 3 </since_tizen>
113 public string AlbumArtist
117 IntPtr val = IntPtr.Zero;
120 MediaContentValidator.ThrowIfError(
121 Interop.AudioInformation.GetAlbumArtist(_handle, out val), "Failed to get value");
123 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
127 Interop.Libc.Free(val);
134 /// If the media content has no album info, the property returns empty string.
136 /// <since_tizen> 3 </since_tizen>
141 IntPtr val = IntPtr.Zero;
144 MediaContentValidator.ThrowIfError(
145 Interop.AudioInformation.GetGenre(_handle, out val), "Failed to get value");
147 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
151 Interop.Libc.Free(val);
157 /// Gets the composer name.
158 /// If the value is an empty string, the property returns "Unknown".
159 /// If the media content has no album info, the property returns empty string.
161 /// <since_tizen> 3 </since_tizen>
162 public string Composer
166 IntPtr val = IntPtr.Zero;
169 MediaContentValidator.ThrowIfError(
170 Interop.AudioInformation.GetComposer(_handle, out val), "Failed to get value");
172 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
176 Interop.Libc.Free(val);
183 /// If the media content has no album info, the property returns empty string.
185 /// <since_tizen> 3 </since_tizen>
190 IntPtr val = IntPtr.Zero;
193 MediaContentValidator.ThrowIfError(
194 Interop.AudioInformation.GetYear(_handle, out val), "Failed to get value");
196 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
200 Interop.Libc.Free(val);
206 /// Gets the recorded date.
208 /// <since_tizen> 3 </since_tizen>
209 public string RecordedDate
213 IntPtr val = IntPtr.Zero;
216 MediaContentValidator.ThrowIfError(
217 Interop.AudioInformation.GetRecordedDate(_handle, out val), "Failed to get value");
219 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
223 Interop.Libc.Free(val);
229 /// Gets the copyright.
230 /// If the media content has no copyright information, the property returns empty string.
232 /// <since_tizen> 3 </since_tizen>
233 public string Copyright
237 IntPtr val = IntPtr.Zero;
240 MediaContentValidator.ThrowIfError(
241 Interop.AudioInformation.GetCopyright(_handle, out val), "Failed to get value");
243 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
247 Interop.Libc.Free(val);
253 /// Gets the track number.
254 /// If the media content has no track information, the property returns empty string.
256 /// <since_tizen> 3 </since_tizen>
257 public string TrackNumber
261 IntPtr val = IntPtr.Zero;
264 MediaContentValidator.ThrowIfError(
265 Interop.AudioInformation.GetTrackNum(_handle, out val), "Failed to get value");
267 return MediaContentValidator.CheckString(Marshal.PtrToStringAnsi(val));
271 Interop.Libc.Free(val);
277 /// Gets the bitrate in bit per second [bps].
279 /// <since_tizen> 3 </since_tizen>
285 MediaContentValidator.ThrowIfError(
286 Interop.AudioInformation.GetBitRate(_handle, out bitrate), "Failed to get value");
293 /// Gets bit per sample.
295 /// <since_tizen> 3 </since_tizen>
296 public int BitPerSample
300 int bitPerSample = 0;
301 MediaContentValidator.ThrowIfError(
302 Interop.AudioInformation.GetBitPerSample(_handle, out bitPerSample), "Failed to get value");
309 /// Gets the sample rate in hz.
311 /// <since_tizen> 3 </since_tizen>
312 public int SampleRate
317 MediaContentValidator.ThrowIfError(
318 Interop.AudioInformation.GetSampleRate(_handle, out sampleRate), "Failed to get value");
325 /// Gets the channel.
327 /// <since_tizen> 3 </since_tizen>
333 MediaContentValidator.ThrowIfError(
334 Interop.AudioInformation.GetChannel(_handle, out channel), "Failed to get value");
341 /// Gets the track duration in Milliseconds.
343 /// <since_tizen> 3 </since_tizen>
349 MediaContentValidator.ThrowIfError(
350 Interop.AudioInformation.GetDuration(_handle, out duration), "Failed to get value");
357 /// Gets the number of MediaBookmark for the passed filter in the given media ID from the media database.
358 /// If NULL is passed to the filter, no filtering is applied.
360 /// <since_tizen> 3 </since_tizen>
362 /// int count</returns>
363 /// <param name="filter">The Filter for matching Bookmarks</param>
364 public int GetMediaBookmarkCount(ContentFilter filter)
367 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
368 MediaContentValidator.ThrowIfError(
369 Interop.MediaInformation.GetBookmarkCount(MediaId, handle, out count), "Failed to get count");
375 /// Returns the MediaBookmarks for the given media info from the media database.
376 /// If NULL is passed to the filter, no filtering is applied.
378 /// <since_tizen> 3 </since_tizen>
380 /// Task to get all the Bookmarks
382 /// <param name="filter"> filter for the Tags</param>
383 public IEnumerable<MediaBookmark> GetMediaBookmarks(ContentFilter filter)
385 Collection<MediaBookmark> coll = new Collection<MediaBookmark>();
386 IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
387 Interop.MediaInformation.MediaBookmarkCallback callback = (IntPtr handle, IntPtr userData) =>
389 IntPtr newHandle = IntPtr.Zero;
390 MediaContentValidator.ThrowIfError(
391 Interop.MediaBookmark.Clone(out newHandle, handle), "Failed to clone");
393 coll.Add(new MediaBookmark(newHandle));
396 MediaContentValidator.ThrowIfError(
397 Interop.MediaInformation.GetAllBookmarks(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value");
403 /// Adds a MediaBookmark to the audio
405 /// <since_tizen> 3 </since_tizen>
406 /// <param name="offset">Offset of the audio in seconds</param>
408 /// Task with newly added MediaBookmark instance.
410 public MediaBookmark AddBookmark(uint offset)
412 MediaBookmark result = null;
413 ContentManager.Database.Insert(MediaId, offset, null);
414 ContentFilter bookmarkfilter = new ContentFilter();
415 bookmarkfilter.Condition = ContentColumns.Bookmark.Offset + " = " + offset;
416 IEnumerable<MediaBookmark> bookmarksList = null;
417 bookmarksList = GetMediaBookmarks(bookmarkfilter);
418 foreach (MediaBookmark bookmark in bookmarksList)
420 if (bookmark.Offset == offset)
427 bookmarkfilter.Dispose();
432 /// Deletes a MediaBookmark item from the media database.
434 /// <since_tizen> 3 </since_tizen>
435 /// <param name="bookmark">The MediaBookmark instance to be deleted</param>
436 public void DeleteBookmark(MediaBookmark bookmark)
438 ContentManager.Database.Delete(bookmark);
441 internal IntPtr AudioHandle
445 return _handle.DangerousGetHandle();
449 internal AudioInformation(Interop.AudioInformation.SafeAudioInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle)
450 : base(mediaInformationHandle)