Setting since_tizen 3/4 on Tizen.NET API
[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);
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             Rating = InteropHelper.GetValue<int>(handle, Interop.MediaInfo.GetRating);
54             IsFavorite = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.GetFavorite);
55             Title = InteropHelper.GetString(handle, Interop.MediaInfo.GetTitle);
56             StorageId = InteropHelper.GetString(handle, Interop.MediaInfo.GetStorageId);
57             IsDrm = InteropHelper.GetValue<bool>(handle, Interop.MediaInfo.IsDrm);
58
59             StorageType = InteropHelper.GetValue<StorageType>(handle, Interop.MediaInfo.GetStorageType);
60         }
61
62         /// <summary>
63         /// Gets the ID of media.
64         /// </summary>
65         /// <value>The unique ID of media.</value>
66         /// <since_tizen> 4 </since_tizen>
67         public string Id { get; }
68
69         /// <summary>
70         /// Gets the path to media.
71         /// </summary>
72         /// <value>The full path of the media file.</value>
73         /// <since_tizen> 4 </since_tizen>
74         public string Path { get; }
75
76         /// <summary>
77         /// Gets the name of media.
78         /// </summary>
79         /// <value>The base name of the media file.</value>
80         /// <since_tizen> 4 </since_tizen>
81         public string DisplayName { get; }
82
83         /// <summary>
84         /// Gets the <see cref="MediaContent.MediaType"/> of media.
85         /// </summary>
86         /// <value>The <see cref="MediaContent.MediaType"/> of media.</value>
87         /// <since_tizen> 4 </since_tizen>
88         public MediaType MediaType { get; }
89
90         /// <summary>
91         /// Gets the mime type from media.
92         /// </summary>
93         /// <value>The mime type of media.</value>
94         /// <since_tizen> 4 </since_tizen>
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         /// <since_tizen> 4 </since_tizen>
102         public long FileSize { get; }
103
104         /// <summary>
105         /// Gets the date of addition of media.
106         /// </summary>
107         /// <value>The date of addition of media.</value>
108         /// <since_tizen> 4 </since_tizen>
109         public DateTimeOffset DateAdded { get; }
110
111         /// <summary>
112         /// Gets the date of modification of media.
113         /// </summary>
114         /// <value>The date of modification of media.</value>
115         /// <since_tizen> 4 </since_tizen>
116         public DateTimeOffset DateModified { get; }
117
118         /// <summary>
119         /// Gets the timeline of media.
120         /// </summary>
121         /// <value>
122         /// The creation date if the file has the creation information (like recorded date or image creation date),
123         /// otherwise the modified date.
124         /// </value>
125         /// <since_tizen> 4 </since_tizen>
126         public DateTimeOffset Timeline { get; }
127
128         /// <summary>
129         /// Gets the thumbnail of media.
130         /// </summary>
131         /// <value>The thumbnail path of media.</value>
132         /// <since_tizen> 4 </since_tizen>
133         public string ThumbnailPath { get; }
134
135         /// <summary>
136         /// Gets the description of media.
137         /// </summary>
138         /// <value>The description from the metadata.</value>
139         /// <since_tizen> 4 </since_tizen>
140         public string Description { get; }
141
142         /// <summary>
143         /// Gets the longitude of media.
144         /// </summary>
145         /// <value>The longitude.</value>
146         /// <since_tizen> 4 </since_tizen>
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         public double Latitude { get; }
155
156         /// <summary>
157         /// Gets the altitude of media.
158         /// </summary>
159         /// <value>The altitude.</value>
160         /// <since_tizen> 4 </since_tizen>
161         public double Altitude { get; }
162
163         /// <summary>
164         /// Gets the rating of media.
165         /// </summary>
166         /// <value>The rating from the metadata.</value>
167         /// <since_tizen> 4 </since_tizen>
168         public int Rating { get; }
169
170         /// <summary>
171         /// Gets the favorite status of media.
172         /// </summary>
173         /// <value>true if media is set as favorite, otherwise false.</value>
174         /// <since_tizen> 4 </since_tizen>
175         public bool IsFavorite { get; }
176
177         /// <summary>
178         /// Gets the title of media.
179         /// </summary>
180         /// <value>The title of media.</value>
181         /// <since_tizen> 4 </since_tizen>
182         public string Title { get; }
183
184         /// <summary>
185         /// Gets the storage ID of the storage that the media is stored on.
186         /// </summary>
187         /// <value>The storage ID of the storage that the media is stored on.</value>
188         /// <since_tizen> 4 </since_tizen>
189         public string StorageId { get; }
190
191         /// <summary>
192         /// Gets the value indicating whether the media is DRM-protected.
193         /// </summary>
194         /// <value>A bool value indicating whether the media is DRM-protected.</value>
195         /// <since_tizen> 4 </since_tizen>
196         public bool IsDrm { get; }
197
198         /// <summary>
199         /// Gets the storage type of the storage that the media is stored on.
200         /// </summary>
201         /// <value>The storage type of the storage that the media is stored on.</value>
202         /// <since_tizen> 4 </since_tizen>
203         public StorageType StorageType { get; }
204
205         /// <summary>
206         /// Returns a string representation of the media information.
207         /// </summary>
208         /// <returns>A string representation of the current media information.</returns>
209         /// <since_tizen> 4 </since_tizen>
210         public override string ToString() => $"Id={Id}, Path={Path}, MediaType={MediaType}";
211
212         internal static MediaInfo FromHandle(Interop.MediaInfoHandle handle)
213         {
214             if (handle == null || handle.IsInvalid)
215             {
216                 return null;
217             }
218
219             var type = InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType);
220
221             switch (type)
222             {
223                 case MediaType.Image:
224                     return new ImageInfo(handle);
225
226                 case MediaType.Music:
227                 case MediaType.Sound:
228                     return new AudioInfo(handle);
229
230                 case MediaType.Video:
231                     return new VideoInfo(handle);
232             }
233
234             return new MediaInfo(handle);
235         }
236
237         internal static MediaInfo FromHandle(IntPtr handle)
238         {
239             var safeHandle = new Interop.MediaInfoHandle(handle);
240             try
241             {
242                 return FromHandle(safeHandle);
243             }
244             finally
245             {
246                 safeHandle.SetHandleAsInvalid();
247             }
248         }
249     }
250 }