2 using System.Collections.Generic;
3 using System.Threading.Tasks;
4 /// Copyright 2016 by Samsung Electronics, Inc.,
6 /// This software is the confidential and proprietary information
7 /// of Samsung Electronics, Inc.("Confidential Information"). You
8 /// shall not disclose such Confidential Information and shall use
9 /// it only in accordance with the terms of the license agreement
10 /// you entered into with Samsung.
13 namespace Tizen.Content.MediaContent
16 /// A Media Group represents logical grouping of media files with respect to their group name.
17 /// It is also used for filtering media items.
19 public class Group : ContentCollection
21 private readonly string _groupName;
22 private bool _disposedValue = false;
25 /// The name of the media group
29 get { return _groupName; }
32 internal Group(string name)
38 /// Dispose API for closing the internal resources.
39 /// This function can be used to stop all effects started by Vibrate().
41 public override void Dispose()
44 GC.SuppressFinalize(this);
47 protected virtual void Dispose(bool disposing)
51 _disposedValue = true;
56 /// Gets the count of the media info for the given media group present in the media database.
58 /// <param name="filter">ContentFilter used to match media content from the media database.</param>
59 /// <returns>The number of media contents matching the filter passed</returns>
60 public override int GetMediaInformationCount(ContentFilter filter)
63 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
64 MediaContentError res = (MediaContentError)Interop.Group.GetMediaCountFromDb(Name, filter.GroupType, handle, out mediaCount);
65 if (res != MediaContentError.None)
67 Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get media count for the group");
74 /// Iterates through the media files with an optional filter in the given group from the media database.
75 /// This function gets all media files associated with the given group and meeting desired filter option.
76 /// If NULL is passed to the filter, no filtering is applied.
78 /// <param name="filter">ContentFilter used to match media content from the media database.</param>
79 /// <returns>List of content media items matching the passed filter</returns>
80 public override Task<IEnumerable<MediaInformation>> GetMediaInformationsAsync(ContentFilter filter)
82 var tcs = new TaskCompletionSource<IEnumerable<MediaInformation>>();
83 List<MediaInformation> mediaContents = new List<MediaInformation>();
84 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
85 MediaContentError res;
86 Interop.Group.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) =>
88 Interop.MediaInformation.SafeMediaInformationHandle newHandle;
89 res = (MediaContentError)Interop.MediaInformation.Clone(out newHandle, mediaHandle);
90 MediaInformation info = new MediaInformation(newHandle);
91 mediaContents.Add(info);
94 res = (MediaContentError)Interop.Group.ForeachMediaFromDb(Name, filter.GroupType, handle, callback, IntPtr.Zero);
95 if (res != MediaContentError.None)
97 Log.Warn(MediaContentErrorFactory.LogTag, "Failed to get media information for the group");
99 tcs.TrySetResult(mediaContents);