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.
19 using System.Collections.Generic;
20 using System.Threading.Tasks;
22 namespace Tizen.Content.MediaContent
25 /// A Media Group represents logical grouping of media files with respect to their group name.
26 /// It is also used for filtering media items.
28 public class Group : ContentCollection
30 private readonly string _groupName;
31 private readonly MediaGroupType _groupType;
32 private bool _disposedValue = false;
35 /// The name of the media group
37 /// <since_tizen> 3 </since_tizen>
40 get { return _groupName; }
43 internal Group(string name, MediaGroupType groupType)
46 _groupType = groupType;
49 public override void Dispose()
52 GC.SuppressFinalize(this);
55 protected virtual void Dispose(bool disposing)
59 _disposedValue = true;
64 /// Gets the count of the media info for the given media group present in the media database.
66 /// <since_tizen> 3 </since_tizen>
67 /// <param name="filter">ContentFilter used to match media content from the media database.</param>
68 /// <returns>The number of media contents matching the filter passed</returns>
69 public override int GetMediaInformationCount(ContentFilter filter)
72 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
73 MediaContentValidator.ThrowIfError(
74 Interop.Group.GetMediaCountFromDb(Name, _groupType, handle, out mediaCount), "Failed to GetMediaCountFromDb");
81 /// Iterates through the media files with an optional filter in the given group from the media database.
82 /// This function gets all media files associated with the given group and meeting desired filter option.
83 /// If NULL is passed to the filter, no filtering is applied.
85 /// <since_tizen> 3 </since_tizen>
86 /// <param name="filter">ContentFilter used to match media content from the media database.</param>
87 /// <returns>List of content media items matching the passed filter</returns>
88 public override IEnumerable<MediaInformation> GetMediaInformations(ContentFilter filter)
90 List<MediaInformation> mediaContents = new List<MediaInformation>();
91 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
92 Interop.Group.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) =>
94 Interop.MediaInformation.SafeMediaInformationHandle newHandle;
95 MediaContentValidator.ThrowIfError(
96 Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone MediaInformation instance");
98 MediaContentType type;
99 Interop.MediaInformation.GetMediaType(newHandle, out type);
100 if (type == MediaContentType.Image)
102 Interop.ImageInformation.SafeImageInformationHandle imageInfo;
103 MediaContentValidator.ThrowIfError(
104 Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information");
106 mediaContents.Add(new ImageInformation(imageInfo, newHandle));
108 else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound))
110 Interop.AudioInformation.SafeAudioInformationHandle audioInfo;
111 MediaContentValidator.ThrowIfError(
112 Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information");
114 mediaContents.Add(new AudioInformation(audioInfo, newHandle));
116 else if (type == MediaContentType.Video)
118 Interop.VideoInformation.SafeVideoInformationHandle videoInfo;
119 MediaContentValidator.ThrowIfError(
120 Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information");
122 mediaContents.Add(new VideoInformation(videoInfo, newHandle));
124 else if (type == MediaContentType.Others)
126 mediaContents.Add(new MediaInformation(newHandle));
131 MediaContentValidator.ThrowIfError(
132 Interop.Group.ForeachMediaFromDb(Name, _groupType, handle, callback, IntPtr.Zero), "Failed to get media information for the group");
134 return mediaContents;