Release 4.0.0-preview1-00172
[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     /// <seealso cref="MediaInfoUpdateValues"/>
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);
45
46             ThumbnailPath = InteropHelper.GetString(handle, Interop.MediaInfo.GetThumbnailPath, true);
47             Description = InteropHelper.GetString(handle, Interop.MediaInfo.GetDescription);
48
49             Longitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetLongitude);
50             Latitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetLatitude);
51             Altitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetAltitude);
52
53             Weather = InteropHelper.GetString(handle, Interop.MediaInfo.GetWeather);
54             Rating = InteropHelper.GetValue<int>(handle, Interop.MediaInfo.GetRating);
55             IsFavorite = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.GetFavorite);
56             Provider = InteropHelper.GetString(handle, Interop.MediaInfo.GetProvider);
57             Title = InteropHelper.GetString(handle, Interop.MediaInfo.GetTitle);
58             Category = InteropHelper.GetString(handle, Interop.MediaInfo.GetCategory);
59             LocationTag = InteropHelper.GetString(handle, Interop.MediaInfo.GetLocationTag);
60             AgeRating = InteropHelper.GetString(handle, Interop.MediaInfo.GetAgeRating);
61             StorageId = InteropHelper.GetString(handle, Interop.MediaInfo.GetStorageId);
62             IsDrm = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.IsDrm);
63
64             StorageType = InteropHelper.GetValue<StorageType>(handle, Interop.MediaInfo.GetStorageType);
65         }
66
67         /// <summary>
68         /// Gets the ID of media.
69         /// </summary>
70         /// <value>The unique ID of media.</value>
71         public string Id { get; }
72
73         /// <summary>
74         /// Gets the path to media.
75         /// </summary>
76         /// <value>The full path of the media file.</value>
77         public string Path { get; }
78
79         /// <summary>
80         /// Gets the name of media.
81         /// </summary>
82         /// <value>The base name of the media file.</value>
83         public string DisplayName { get; }
84
85         /// <summary>
86         /// Gets the <see cref="MediaType"/> of media.
87         /// </summary>
88         /// <value>The <see cref="MediaType"/> of media.</value>
89         public MediaType MediaType { get; }
90
91         /// <summary>
92         /// Gets the mime type from media.
93         /// </summary>
94         /// <value>The mime type of media.</value>
95         public string MimeType { get; }
96
97         /// <summary>
98         /// Gets the file size of media in bytes.
99         /// </summary>
100         /// <value>The file size of media in bytes.</value>
101         public long FileSize { get; }
102
103         /// <summary>
104         /// Gets the date of addition of media.
105         /// </summary>
106         /// <value>The date of addition of media.</value>
107         public DateTimeOffset DateAdded { get; }
108
109         /// <summary>
110         /// Gets the date of modification of media.
111         /// </summary>
112         /// <value>The date of modification of media.</value>
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         public DateTimeOffset Timeline { get; }
123
124         /// <summary>
125         /// Gets the thumbnail of media.
126         /// </summary>
127         /// <value>The thumbnail path of media.</value>
128         public string ThumbnailPath { get; }
129
130         /// <summary>
131         /// Gets the description of media.
132         /// </summary>
133         /// <value>The description from the metadata.</value>
134         public string Description { get; }
135
136         /// <summary>
137         /// Gets the longitude of media.
138         /// </summary>
139         /// <value>The longitude.</value>
140         public double Longitude { get; }
141
142         /// <summary>
143         /// Gets the latitude of media.
144         /// </summary>
145         /// <value>The latitude.</value>
146         public double Latitude { get; }
147
148         /// <summary>
149         /// Gets the altitude of media.
150         /// </summary>
151         /// <value>The altitude.</value>
152         public double Altitude { get; }
153
154         /// <summary>
155         /// Gets the weather information of media.
156         /// </summary>
157         /// <value>The weather information which a user sets.</value>
158         public string Weather { get; }
159
160         /// <summary>
161         /// Gets the rating of media.
162         /// </summary>
163         /// <value>The rating from the metadata.</value>
164         public int Rating { get; }
165
166         /// <summary>
167         /// Gets the favorite status of media.
168         /// </summary>
169         /// <value>true if media is set as favorite, otherwise false.</value>
170         public bool IsFavorite { get; }
171
172         /// <summary>
173         /// Gets the provider of media.
174         /// </summary>
175         /// <value>The provider which a user sets.</value>
176         public string Provider { get; }
177
178         /// <summary>
179         /// Gets the title of media.
180         /// </summary>
181         /// <value>The title of media.</value>
182         public string Title { get; }
183
184         /// <summary>
185         /// Gets the category of media.
186         /// </summary>
187         /// <value>The category which a user sets.</value>
188         public string Category { get; }
189
190         /// <summary>
191         /// Gets the location tag of media.
192         /// </summary>
193         /// <value>The location tag which a user sets.</value>
194         public string LocationTag { get; }
195
196         /// <summary>
197         /// Gets the age rating of media.
198         /// </summary>
199         /// <value>The age rating which a user sets.</value>
200         public string AgeRating { get; }
201
202         /// <summary>
203         /// Gets the storage ID of the storage that the media is stored on.
204         /// </summary>
205         /// <value>The storage ID of the storage that the media is stored on.</value>
206         public string StorageId { get; }
207
208         /// <summary>
209         /// Gets the value indicating whether the media is DRM-protected.
210         /// </summary>
211         /// <value>A bool value indicating whether the media is DRM-protected.</value>
212         public bool IsDrm { get; }
213
214         /// <summary>
215         /// Gets the storage type of the storage that the media is stored on.
216         /// </summary>
217         /// <value>The storage type of the storage that the media is stored on.</value>
218         public StorageType StorageType { get; }
219
220         /// <summary>
221         /// Returns a string representation of the media information.
222         /// </summary>
223         /// <returns>A string representation of the current media information.</returns>
224         public override string ToString() => $"Id={Id}, Path={Path}, MediaType={MediaType}";
225
226         internal static MediaInfo FromHandle(Interop.MediaInfoHandle handle)
227         {
228             if (handle == null || handle.IsInvalid)
229             {
230                 return null;
231             }
232
233             var type = InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType);
234
235             switch (type)
236             {
237                 case MediaType.Image:
238                     return new ImageInfo(handle);
239
240                 case MediaType.Music:
241                 case MediaType.Sound:
242                     return new AudioInfo(handle);
243
244                 case MediaType.Video:
245                     return new VideoInfo(handle);
246             }
247
248             return new MediaInfo(handle);
249         }
250
251         internal static MediaInfo FromHandle(IntPtr handle)
252         {
253             var safeHandle = new Interop.MediaInfoHandle(handle);
254             try
255             {
256                 return FromHandle(safeHandle);
257             }
258             finally
259             {
260                 safeHandle.SetHandleAsInvalid();
261             }
262         }
263     }
264 }