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;
24 namespace Tizen.Content.MediaContent
27 /// An album is a logical collection or grouping of related audio files. It is also used for filtering media items.
28 /// The Media Album API allows to manage media albums which contains all video and audio items from the same album.
30 public class Album : ContentCollection
32 private IntPtr _albumHandle = IntPtr.Zero;
38 if (_albumHandle == IntPtr.Zero)
40 throw new ObjectDisposedException(nameof(Album));
48 /// The media album ID
50 /// <since_tizen> 3 </since_tizen>
56 MediaContentValidator.ThrowIfError(
57 Interop.Group.MediaAlbumGetAlbumId(Handle, out id), "Failed to get value");
64 /// The name of the media artist
65 /// If the media content has no album info, the property returns empty string.
67 /// <since_tizen> 3 </since_tizen>
72 IntPtr val = IntPtr.Zero;
75 MediaContentValidator.ThrowIfError(
76 Interop.Group.MediaAlbumGetArtist(Handle, out val), "Failed to get value");
78 return Marshal.PtrToStringAnsi(val);
82 Interop.Libc.Free(val);
88 /// The path of the media album art
90 /// <since_tizen> 3 </since_tizen>
95 IntPtr val = IntPtr.Zero;
98 MediaContentValidator.ThrowIfError(
99 Interop.Group.MediaAlbumGetAlbumArt(Handle, out val), "Failed to get value");
101 return Marshal.PtrToStringAnsi(val);
105 Interop.Libc.Free(val);
111 /// The name of the media album
112 /// If the media content has no album info, the property returns empty string.
114 /// <since_tizen> 3 </since_tizen>
119 IntPtr val = IntPtr.Zero;
122 MediaContentValidator.ThrowIfError(
123 Interop.Group.MediaAlbumGetName(Handle, out val), "Failed to get value");
125 return Marshal.PtrToStringAnsi(val);
129 Interop.Libc.Free(val);
134 internal Album(IntPtr handle)
136 _albumHandle = handle;
140 /// Gets the number of MediaInformation Items for the given album present in the media database.
141 /// If NULL is passed to the filter, no filtering is applied.
143 /// <since_tizen> 3 </since_tizen>
144 /// <param name="filter">ContentFilter used to match media content from the media database.</param>
145 /// <returns>The number of media contents matching the filter passed</returns>
146 public override int GetMediaInformationCount(ContentFilter filter)
149 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
151 MediaContentValidator.ThrowIfError(
152 Interop.Group.MediaAlbumGetMediaCountFromDb(Id, handle, out mediaCount), "Failed to get count");
157 public override void Dispose()
159 if (_albumHandle != IntPtr.Zero)
161 Interop.Group.MediaAlbumDestroy(_albumHandle);
162 _albumHandle = IntPtr.Zero;
167 /// Iterates through the media files with a filter in the given media album from the media database.
168 /// This function gets all media files associated with the given media album and meeting desired filter option.
169 /// If NULL is passed to the filter, no filtering is applied.
171 /// <since_tizen> 3 </since_tizen>
172 /// <param name="filter">ContentFilter used to match media content from the media database.</param>
173 /// <returns>List of content media items matching the passed filter</returns>
174 public override IEnumerable<MediaInformation> GetMediaInformations(ContentFilter filter)
176 List<MediaInformation> mediaContents = new List<MediaInformation>();
178 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
179 Interop.Group.MediaInfoCallback callback = (IntPtr mediaHandle, IntPtr data) =>
181 Interop.MediaInformation.SafeMediaInformationHandle newHandle;
182 MediaContentValidator.ThrowIfError(
183 Interop.MediaInformation.Clone(out newHandle, mediaHandle), "Failed to clone");
185 MediaContentType type;
186 Interop.MediaInformation.GetMediaType(newHandle, out type);
187 if (type == MediaContentType.Image)
189 Interop.ImageInformation.SafeImageInformationHandle imageInfo;
190 MediaContentValidator.ThrowIfError(
191 Interop.MediaInformation.GetImage(mediaHandle, out imageInfo), "Failed to get image information");
193 mediaContents.Add(new ImageInformation(imageInfo, newHandle));
195 else if ((type == MediaContentType.Music) || (type == MediaContentType.Sound))
197 Interop.AudioInformation.SafeAudioInformationHandle audioInfo;
198 MediaContentValidator.ThrowIfError(
199 Interop.MediaInformation.GetAudio(mediaHandle, out audioInfo), "Failed to get audio information");
201 mediaContents.Add(new AudioInformation(audioInfo, newHandle));
203 else if (type == MediaContentType.Video)
205 Interop.VideoInformation.SafeVideoInformationHandle videoInfo;
206 MediaContentValidator.ThrowIfError(
207 Interop.MediaInformation.GetVideo(mediaHandle, out videoInfo), "Failed to get video information");
209 mediaContents.Add(new VideoInformation(videoInfo, newHandle));
211 else if (type == MediaContentType.Others)
213 mediaContents.Add(new MediaInformation(newHandle));
218 MediaContentValidator.ThrowIfError(
219 Interop.Group.MediaAlbumForeachMediaFromDb(Id, handle, callback, IntPtr.Zero), "Failed to get information");
221 return mediaContents;