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.
18 using Native = Interop.MediaControllerPlaylist;
20 namespace Tizen.Multimedia.Remoting
23 /// Represents metadata for media control.
25 /// <since_tizen> 4 </since_tizen>
26 public class MediaControlMetadata
29 /// Initializes a new instance of the <see cref="MediaControlMetadata"/> class.
31 /// <since_tizen> 4 </since_tizen>
32 public MediaControlMetadata()
36 internal MediaControlMetadata(IntPtr handle)
38 // If native framework return null handle,
39 // it means server doesn't set metadata yet and it's not error.
40 // So we need to return empty metadata instance as native framework does.
41 if (handle == IntPtr.Zero)
46 Title = Native.GetMetadata(handle, MediaControllerNativeAttribute.Title);
47 Artist = Native.GetMetadata(handle, MediaControllerNativeAttribute.Artist);
48 Album = Native.GetMetadata(handle, MediaControllerNativeAttribute.Album);
49 Author = Native.GetMetadata(handle, MediaControllerNativeAttribute.Author);
50 Genre = Native.GetMetadata(handle, MediaControllerNativeAttribute.Genre);
51 Duration = Native.GetMetadata(handle, MediaControllerNativeAttribute.Duration);
52 Date = Native.GetMetadata(handle, MediaControllerNativeAttribute.Date);
53 Copyright = Native.GetMetadata(handle, MediaControllerNativeAttribute.Copyright);
54 Description = Native.GetMetadata(handle, MediaControllerNativeAttribute.Description);
55 TrackNumber = Native.GetMetadata(handle, MediaControllerNativeAttribute.TrackNumber);
56 AlbumArtPath = Native.GetMetadata(handle, MediaControllerNativeAttribute.Picture);
58 EncodedSeason = Native.GetMetadata(handle, MediaControllerNativeAttribute.Season);
59 EncodedEpisode = Native.GetMetadata(handle, MediaControllerNativeAttribute.Episode);
60 EncodedResolution = Native.GetMetadata(handle, MediaControllerNativeAttribute.Resolution);
64 /// Gets or sets the title.
66 /// <since_tizen> 4 </since_tizen>
67 public string Title { get; set; }
70 /// Gets or sets the artist.
72 /// <since_tizen> 4 </since_tizen>
73 public string Artist { get; set; }
76 /// Gets or sets the album.
78 /// <since_tizen> 4 </since_tizen>
79 public string Album { get; set; }
82 /// Gets or sets the author.
84 /// <since_tizen> 4 </since_tizen>
85 public string Author { get; set; }
88 /// Gets or sets the genre.
90 /// <since_tizen> 4 </since_tizen>
91 public string Genre { get; set; }
94 /// Gets or sets the duration.
96 /// <since_tizen> 4 </since_tizen>
97 public string Duration { get; set; }
100 /// Gets or sets the date.
102 /// <since_tizen> 4 </since_tizen>
103 public string Date { get; set; }
106 /// Gets or sets the copyright.
108 /// <since_tizen> 4 </since_tizen>
109 public string Copyright { get; set; }
112 /// Gets or sets the description.
114 /// <since_tizen> 4 </since_tizen>
115 public string Description { get; set; }
118 /// Gets or sets the track number.
120 /// <since_tizen> 4 </since_tizen>
121 public string TrackNumber { get; set; }
124 /// Gets or sets the path of the album art.
126 /// <since_tizen> 4 </since_tizen>
127 public string AlbumArtPath { get; set; }
130 /// Gets or sets the season information.
132 /// <seealso cref="SeriesInformation"/>
133 /// <since_tizen> 6 </since_tizen>
134 public SeriesInformation Season
136 get => DecodeSeason(EncodedSeason);
137 set => EncodedSeason = EncodeSeason(value);
141 /// Gets or sets the episode information.
143 /// <seealso cref="SeriesInformation"/>
144 /// <since_tizen> 6 </since_tizen>
145 public SeriesInformation Episode
147 get => DecodeEpisode(EncodedEpisode);
148 set => EncodedEpisode = EncodeEpisode(value);
152 /// Gets or sets the content resolution.
154 /// <seealso cref="Size"/>
155 /// <since_tizen> 6 </since_tizen>
156 public Size Resolution
158 get => DecodeResolution(EncodedResolution);
159 set => EncodedResolution = EncodeResolution(value.Width, value.Height);
162 // Developers who use Tizen Native API must encode strings to set or get metadata of media
163 // such as season, episode, and resolution. It is inconvenient.
164 // TizenFX supports for using normal strings and using encoded strings internally.
165 internal string EncodedSeason { get; private set; }
167 internal string EncodedEpisode { get; private set; }
169 internal string EncodedResolution { get; private set; }
171 private static string EncodeSeason(SeriesInformation information)
173 Native.EncodeSeason(information.Number, information.Title, out string encodedSeason).
174 ThrowIfError("Failed to encode season");
176 return encodedSeason;
179 private static string EncodeEpisode(SeriesInformation information)
181 Native.EncodeEpisode(information.Number, information.Title, out string encodedEpisode).
182 ThrowIfError("Failed to encode episode");
184 return encodedEpisode;
187 private static string EncodeResolution(int width, int height)
189 Native.EncodeResolution((uint)width, (uint)height, out string encodedResolution).
190 ThrowIfError("Failed to encode resolution");
192 return encodedResolution;
195 private static SeriesInformation DecodeSeason(string encodedSeason)
200 if (encodedSeason != null)
202 Native.DecodeSeason(encodedSeason, out number, out title).
203 ThrowIfError("Failed to decode season");
206 return new SeriesInformation(number, title);
209 private static SeriesInformation DecodeEpisode(string encodedEpisode)
214 if (encodedEpisode != null)
216 Native.DecodeEpisode(encodedEpisode, out number, out title).
217 ThrowIfError("Failed to decode episode");
220 return new SeriesInformation(number, title);
223 private static Size DecodeResolution(string encodedResolution)
225 uint width = 0, height = 0;
227 if (encodedResolution != null)
229 Native.DecodeResolution(encodedResolution, out width, out height).
230 ThrowIfError("Failed to decode resolution");
233 return new Size((int)width, (int)height);
238 /// Represents properties for the video series information.
240 /// <since_tizen> 6 </since_tizen>
241 public class SeriesInformation
244 /// Initializes a new instance of the <see cref="SeriesInformation"/> class.
246 /// <param name="number">The order of this video in entire series.</param>
247 /// <param name="title">The title.</param>
248 /// <since_tizen> 6 </since_tizen>
249 public SeriesInformation(int number, string title)
256 /// Gets or sets the order of this video in entire series.
258 /// <since_tizen> 6 </since_tizen>
259 public int Number { get; }
262 /// Gets or sets the title.
264 /// <since_tizen> 6 </since_tizen>
265 public string Title { get; }
268 /// Returns a string that represents the current object.
270 /// <returns>A string that represents the current object.</returns>
271 /// <since_tizen> 6 </since_tizen>
272 public override string ToString() => $"Number={Number.ToString()}, Title={Title}";