1ad0158241d984c7d105295a66838a5ef40800f6
[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 #pragma warning disable CS0618 // Type or member is obsolete
30         internal MediaInfo(Interop.MediaInfoHandle handle)
31         {
32             Id = InteropHelper.GetString(handle, Interop.MediaInfo.GetMediaId);
33
34             Path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath);
35             DisplayName = InteropHelper.GetString(handle, Interop.MediaInfo.GetDisplayName);
36
37             MediaType = InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType);
38
39             MimeType = InteropHelper.GetString(handle, Interop.MediaInfo.GetMimeType);
40
41             FileSize = InteropHelper.GetValue<long>(handle, Interop.MediaInfo.GetSize);
42
43             DateAdded = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetAddedTime);
44             DateModified = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetModifiedTime);
45             Timeline = InteropHelper.GetDateTime(handle, Interop.MediaInfo.GetTimeline);
46
47             ThumbnailPath = InteropHelper.GetString(handle, Interop.MediaInfo.GetThumbnailPath, true);
48             Description = InteropHelper.GetString(handle, Interop.MediaInfo.GetDescription);
49
50             Longitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetLongitude);
51             Latitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetLatitude);
52             Altitude = InteropHelper.GetValue<double>(handle, Interop.MediaInfo.GetAltitude);
53
54             Rating = InteropHelper.GetValue<int>(handle, Interop.MediaInfo.GetRating);
55             IsFavorite = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.GetFavorite);
56             Title = InteropHelper.GetString(handle, Interop.MediaInfo.GetTitle);
57             StorageId = InteropHelper.GetString(handle, Interop.MediaInfo.GetStorageId);
58             IsDrm = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.IsDrm);
59
60             StorageType = InteropHelper.GetValue<StorageType>(handle, Interop.MediaInfo.GetStorageType);
61         }
62 #pragma warning restore CS0618 // Type or member is obsolete
63
64         /// <summary>
65         /// Gets the ID of media.
66         /// </summary>
67         /// <value>The unique ID of media.</value>
68         /// <since_tizen> 4 </since_tizen>
69         public string Id { get; }
70
71         /// <summary>
72         /// Gets the path to media.
73         /// </summary>
74         /// <value>The full path of the media file.</value>
75         /// <since_tizen> 4 </since_tizen>
76         public string Path { get; }
77
78         /// <summary>
79         /// Gets the name of media.
80         /// </summary>
81         /// <value>The base name of the media file.</value>
82         /// <since_tizen> 4 </since_tizen>
83         public string DisplayName { get; }
84
85         /// <summary>
86         /// Gets the <see cref="MediaContent.MediaType"/> of media.
87         /// </summary>
88         /// <value>The <see cref="MediaContent.MediaType"/> of media.</value>
89         /// <since_tizen> 4 </since_tizen>
90         public MediaType MediaType { get; }
91
92         /// <summary>
93         /// Gets the mime type from media.
94         /// </summary>
95         /// <value>The mime type of media.</value>
96         /// <since_tizen> 4 </since_tizen>
97         public string MimeType { get; }
98
99         /// <summary>
100         /// Gets the file size of media in bytes.
101         /// </summary>
102         /// <value>The file size of media in bytes.</value>
103         /// <since_tizen> 4 </since_tizen>
104         public long FileSize { get; }
105
106         /// <summary>
107         /// Gets the date of addition of media.
108         /// </summary>
109         /// <value>The date of addition of media.</value>
110         /// <since_tizen> 4 </since_tizen>
111         public DateTimeOffset DateAdded { get; }
112
113         /// <summary>
114         /// Gets the date of modification of media.
115         /// </summary>
116         /// <value>The date of modification of media.</value>
117         /// <since_tizen> 4 </since_tizen>
118         public DateTimeOffset DateModified { get; }
119
120         /// <summary>
121         /// Gets the timeline of media.
122         /// </summary>
123         /// <value>
124         /// The creation date if the file has the creation information (like recorded date or image creation date),
125         /// otherwise the modified date.
126         /// </value>
127         /// <since_tizen> 4 </since_tizen>
128         public DateTimeOffset Timeline { get; }
129
130         /// <summary>
131         /// Gets the thumbnail of media.
132         /// </summary>
133         /// <value>The thumbnail path of media.</value>
134         /// <since_tizen> 4 </since_tizen>
135         public string ThumbnailPath { get; }
136
137         /// <summary>
138         /// Gets the description of media.
139         /// </summary>
140         /// <value>The description from the metadata.</value>
141         /// <since_tizen> 4 </since_tizen>
142         public string Description { get; }
143
144         /// <summary>
145         /// Gets the longitude of media.
146         /// </summary>
147         /// <value>The longitude.</value>
148         /// <since_tizen> 4 </since_tizen>
149         public double Longitude { get; }
150
151         /// <summary>
152         /// Gets the latitude of media.
153         /// </summary>
154         /// <value>The latitude.</value>
155         /// <since_tizen> 4 </since_tizen>
156         public double Latitude { get; }
157
158         /// <summary>
159         /// Gets the altitude of media.
160         /// </summary>
161         /// <value>The altitude.</value>
162         /// <since_tizen> 4 </since_tizen>
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         public int Rating { get; }
171
172         /// <summary>
173         /// Gets the favorite status of media.
174         /// </summary>
175         /// <value>true if media is set as favorite, otherwise false.</value>
176         /// <since_tizen> 4 </since_tizen>
177         public bool IsFavorite { get; }
178
179         /// <summary>
180         /// Gets the title of media.
181         /// </summary>
182         /// <value>The title of media.</value>
183         /// <since_tizen> 4 </since_tizen>
184         public string Title { get; }
185
186         /// <summary>
187         /// Gets the storage ID of the storage that the media is stored on.
188         /// </summary>
189         /// <value>The storage ID of the storage that the media is stored on.</value>
190         /// <since_tizen> 4 </since_tizen>
191         [Obsolete("Please do not use! this will be deprecated in level 6")]
192         public string StorageId { get; }
193
194         /// <summary>
195         /// Gets the value indicating whether the media is DRM-protected.
196         /// </summary>
197         /// <value>A bool value indicating whether the media is DRM-protected.</value>
198         /// <since_tizen> 4 </since_tizen>
199         public bool IsDrm { get; }
200
201         /// <summary>
202         /// Gets the storage type of the storage that the media is stored on.
203         /// </summary>
204         /// <value>The storage type of the storage that the media is stored on.</value>
205         /// <since_tizen> 4 </since_tizen>
206         [Obsolete("Please do not use! this will be deprecated in level 6")]
207         public StorageType StorageType { get; }
208
209         /// <summary>
210         /// Returns a string representation of the media information.
211         /// </summary>
212         /// <returns>A string representation of the current media information.</returns>
213         /// <since_tizen> 4 </since_tizen>
214         public override string ToString() => $"Id={Id}, Path={Path}, MediaType={MediaType}";
215
216         internal static MediaInfo FromHandle(Interop.MediaInfoHandle handle)
217         {
218             if (handle == null || handle.IsInvalid)
219             {
220                 return null;
221             }
222
223             var type = InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType);
224
225             switch (type)
226             {
227                 case MediaType.Image:
228                     return new ImageInfo(handle);
229
230                 case MediaType.Music:
231                 case MediaType.Sound:
232                     return new AudioInfo(handle);
233
234                 case MediaType.Video:
235                     return new VideoInfo(handle);
236
237                 case MediaType.Book:
238                     return new BookInfo(handle);
239             }
240
241             return new MediaInfo(handle);
242         }
243
244         internal static MediaInfo FromHandle(IntPtr handle)
245         {
246             var safeHandle = new Interop.MediaInfoHandle(handle);
247             try
248             {
249                 return FromHandle(safeHandle);
250             }
251             finally
252             {
253                 safeHandle.SetHandleAsInvalid();
254             }
255         }
256     }
257 }