a7c6e1d1bde31d437e3929ed092c4dfa213dbe57
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / MediaInfo.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Content.MediaContent
20 {
21
22     /// <summary>
23     /// Represents the information related to the media stored.
24     /// </summary>
25     /// <seealso cref="MediaInfoCommand"/>
26     /// <since_tizen> 4 </since_tizen>
27     public class MediaInfo
28     {
29         internal MediaInfo(Interop.MediaInfoHandle handle)
30         {
31             Id = InteropHelper.GetString(handle, Interop.MediaInfo.GetMediaId);
32
33             Path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath);
34             DisplayName = InteropHelper.GetString(handle, Interop.MediaInfo.GetDisplayName);
35
36             MediaType = InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType);
37
38             MimeType = InteropHelper.GetString(handle, Interop.MediaInfo.GetMimeType);
39
40             FileSize = InteropHelper.GetValue<long>(handle, Interop.MediaInfo.GetSize);
41
42             DateAdded = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetAddedTime);
43             DateModified = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetModifiedTime);
44             Timeline = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetTimeline);  // Deprecated since API12
45
46             ThumbnailPath = InteropHelper.GetString(handle, Interop.MediaInfo.GetThumbnailPath, true);
47             Description = InteropHelper.GetString(handle, Interop.MediaInfo.GetDescription);  // Deprecated since API12
48
49             Longitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetLongitude);  // Deprecated since API12
50             Latitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetLatitude);  // Deprecated since API12
51             Altitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetAltitude);  // Deprecated since API12
52
53             Rating = InteropHelper.GetValue<int>(handle, Interop.MediaInfo.GetRating);  // Deprecated since API12
54             IsFavorite = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.GetFavorite);  // Deprecated since API12
55             Title = InteropHelper.GetString(handle, Interop.MediaInfo.GetTitle);
56             IsDrm = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.IsDrm);  // Deprecated since API12
57         }
58
59         /// <summary>
60         /// Gets the ID of media.
61         /// </summary>
62         /// <value>The unique ID of media.</value>
63         /// <since_tizen> 4 </since_tizen>
64         public string Id { get; }
65
66         /// <summary>
67         /// Gets the path to media.
68         /// </summary>
69         /// <value>The full path of the media file.</value>
70         /// <since_tizen> 4 </since_tizen>
71         public string Path { get; }
72
73         /// <summary>
74         /// Gets the name of media.
75         /// </summary>
76         /// <value>The base name of the media file.</value>
77         /// <since_tizen> 4 </since_tizen>
78         public string DisplayName { get; }
79
80         /// <summary>
81         /// Gets the <see cref="MediaContent.MediaType"/> of media.
82         /// </summary>
83         /// <value>The <see cref="MediaContent.MediaType"/> of media.</value>
84         /// <since_tizen> 4 </since_tizen>
85         public MediaType MediaType { get; }
86
87         /// <summary>
88         /// Gets the mime type from media.
89         /// </summary>
90         /// <value>The mime type of media.</value>
91         /// <since_tizen> 4 </since_tizen>
92         public string MimeType { get; }
93
94         /// <summary>
95         /// Gets the file size of media in bytes.
96         /// </summary>
97         /// <value>The file size of media in bytes.</value>
98         /// <since_tizen> 4 </since_tizen>
99         public long FileSize { get; }
100
101         /// <summary>
102         /// Gets the date of addition of media.
103         /// </summary>
104         /// <value>The date of addition of media.</value>
105         /// <since_tizen> 4 </since_tizen>
106         public DateTimeOffset DateAdded { get; }
107
108         /// <summary>
109         /// Gets the date of modification of media.
110         /// </summary>
111         /// <value>The date of modification of media.</value>
112         /// <since_tizen> 4 </since_tizen>
113         public DateTimeOffset DateModified { get; }
114
115         /// <summary>
116         /// Gets the timeline of media.
117         /// </summary>
118         /// <value>
119         /// The creation date if the file has the creation information (like recorded date or image creation date),
120         /// otherwise the modified date.
121         /// </value>
122         /// <since_tizen> 4 </since_tizen>
123         [Obsolete("Deprecated since API12; Will be removed in API14.")]
124         public DateTimeOffset Timeline { get; }
125
126         /// <summary>
127         /// Gets the thumbnail of media.
128         /// </summary>
129         /// <value>The thumbnail path of media.</value>
130         /// <since_tizen> 4 </since_tizen>
131         public string ThumbnailPath { get; }
132
133         /// <summary>
134         /// Gets the description of media.
135         /// </summary>
136         /// <value>The description from the metadata.</value>
137         /// <since_tizen> 4 </since_tizen>
138         [Obsolete("Deprecated since API12; Will be removed in API14.")]
139         public string Description { get; }
140
141         /// <summary>
142         /// Gets the longitude of media.
143         /// </summary>
144         /// <value>The longitude.</value>
145         /// <since_tizen> 4 </since_tizen>
146         [Obsolete("Deprecated since API12; Will be removed in API14.")]
147         public double Longitude { get; }
148
149         /// <summary>
150         /// Gets the latitude of media.
151         /// </summary>
152         /// <value>The latitude.</value>
153         /// <since_tizen> 4 </since_tizen>
154         [Obsolete("Deprecated since API12; Will be removed in API14.")]
155         public double Latitude { get; }
156
157         /// <summary>
158         /// Gets the altitude of media.
159         /// </summary>
160         /// <value>The altitude.</value>
161         /// <since_tizen> 4 </since_tizen>
162         [Obsolete("Deprecated since API12; Will be removed in API14.")]
163         public double Altitude { get; }
164
165         /// <summary>
166         /// Gets the rating of media.
167         /// </summary>
168         /// <value>The rating from the metadata.</value>
169         /// <since_tizen> 4 </since_tizen>
170         [Obsolete("Deprecated since API12; Will be removed in API14.")]
171         public int Rating { get; }
172
173         /// <summary>
174         /// Gets the favorite status of media.
175         /// </summary>
176         /// <value>true if media is set as favorite, otherwise false.</value>
177         /// <since_tizen> 4 </since_tizen>
178         [Obsolete("Deprecated since API12; Will be removed in API14.")]
179         public bool IsFavorite { get; }
180
181         /// <summary>
182         /// Gets the title of media.
183         /// </summary>
184         /// <value>The title of media.</value>
185         /// <since_tizen> 4 </since_tizen>
186         public string Title { get; }
187
188         /// <summary>
189         /// Gets the value indicating whether the media is DRM-protected.
190         /// </summary>
191         /// <value>A bool value indicating whether the media is DRM-protected.</value>
192         /// <since_tizen> 4 </since_tizen>
193         [Obsolete("Deprecated since API12; Will be removed in API14.")]
194         public bool IsDrm { get; }
195
196         /// <summary>
197         /// Returns a string representation of the media information.
198         /// </summary>
199         /// <returns>A string representation of the current media information.</returns>
200         /// <since_tizen> 4 </since_tizen>
201         public override string ToString() => $"Id={Id}, Path={Path}, MediaType={MediaType}";
202
203         internal static MediaInfo FromHandle(Interop.MediaInfoHandle handle)
204         {
205             if (handle == null || handle.IsInvalid)
206             {
207                 return null;
208             }
209
210             var type = InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType);
211
212             switch (type)
213             {
214                 case MediaType.Image:
215                     return new ImageInfo(handle);
216
217                 case MediaType.Music:
218                 case MediaType.Sound:
219                     return new AudioInfo(handle);
220
221                 case MediaType.Video:
222                     return new VideoInfo(handle);
223
224                 case MediaType.Book:
225                     return new BookInfo(handle);
226             }
227
228             return new MediaInfo(handle);
229         }
230
231         internal static MediaInfo FromHandle(IntPtr handle)
232         {
233             var safeHandle = new Interop.MediaInfoHandle(handle);
234             try
235             {
236                 return FromHandle(safeHandle);
237             }
238             finally
239             {
240                 safeHandle.SetHandleAsInvalid();
241             }
242         }
243     }
244 }