[Multimedia] Modified a constructor of the Display class not to check the raw video...
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / PlayerTrackInfo.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 using System;
17 using System.Diagnostics;
18 using System.Runtime.InteropServices;
19 using static Interop;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Provides a means to retrieve the track information.
25     /// </summary>
26     /// <seealso cref="Player.SubtitleTrackInfo"/>
27     /// <seealso cref="Player.AudioTrackInfo"/>
28     /// <since_tizen> 3 </since_tizen>
29     public class PlayerTrackInfo
30     {
31         private readonly int _streamType;
32         private readonly Player _owner;
33
34         internal PlayerTrackInfo(Player player, StreamType streamType)
35         {
36             Debug.Assert(player != null);
37
38             Log.Debug(PlayerLog.Tag, "streamType : " + streamType);
39             _streamType = (int)streamType;
40             _owner = player;
41         }
42
43         /// <summary>
44         /// Gets the number of tracks.
45         /// </summary>
46         /// <returns>The number of tracks.</returns>
47         /// <remarks>
48         /// The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
49         /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
50         /// </remarks>
51         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
52         /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.</exception>
53         /// <since_tizen> 3 </since_tizen>
54         public int GetCount()
55         {
56             _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
57
58             int count = 0;
59             NativePlayer.GetTrackCount(_owner.Handle, _streamType, out count).
60                 ThrowIfFailed("Failed to get count of the track");
61             Log.Info(PlayerLog.Tag, "get count : " + count);
62             return count;
63         }
64
65         /// <summary>
66         /// Gets the language code for the specified index, or null if the language is undefined.
67         /// </summary>
68         /// <returns>The number of tracks.</returns>
69         /// <remarks>
70         ///     <para>The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
71         ///     <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.</para>
72         ///     <para>The language codes are defined in ISO 639-1.</para>
73         /// </remarks>
74         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
75         /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.</exception>
76         /// <exception cref="ArgumentOutOfRangeException">
77         ///     <paramref name="index"/> is less than zero.<br/>
78         ///     -or-<br/>
79         ///     <paramref name="index"/> is equal to or greater than <see cref="GetCount()"/>.
80         /// </exception>
81         /// <since_tizen> 3 </since_tizen>
82         public string GetLanguageCode(int index)
83         {
84             _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
85
86             if (index < 0 || GetCount() <= index)
87             {
88                 Log.Error(PlayerLog.Tag, "invalid index");
89                 throw new ArgumentOutOfRangeException(nameof(index), index,
90                     $"valid index range is 0 <= x < {nameof(GetCount)}(), but got { index }.");
91             }
92
93             IntPtr code = IntPtr.Zero;
94
95             try
96             {
97                 NativePlayer.GetTrackLanguageCode(_owner.Handle, _streamType, index, out code).
98                     ThrowIfFailed("Failed to get the selected language of the player");
99
100                 string result = Marshal.PtrToStringAnsi(code);
101
102                 if (result == "und")
103                 {
104                     Log.Error(PlayerLog.Tag, "not defined code");
105                     return null;
106                 }
107                 Log.Info(PlayerLog.Tag, "get language code : " + result);
108                 return result;
109             }
110             finally
111             {
112                 LibcSupport.Free(code);
113             }
114         }
115
116         /// <summary>
117         /// Gets or sets the selected track index.
118         /// </summary>
119         /// <value>The currently selected track index.</value>
120         /// <remarks>
121         /// The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
122         /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
123         /// </remarks>
124         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
125         /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.</exception>
126         /// <exception cref="ArgumentOutOfRangeException">
127         ///     <paramref name="value"/> is less than zero.<br/>
128         ///     -or-<br/>
129         ///     <paramref name="value"/> is equal to or greater than <see cref="GetCount()"/>.
130         /// </exception>
131         /// <since_tizen> 3 </since_tizen>
132         public int Selected
133         {
134             get
135             {
136                 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
137
138                 int value = 0;
139
140                 NativePlayer.GetCurrentTrack(_owner.Handle, _streamType, out value).
141                     ThrowIfFailed("Failed to get the selected index of the player");
142                 Log.Debug(PlayerLog.Tag, "get selected index : " + value);
143                 return value;
144             }
145             set
146             {
147                 if (value < 0 || GetCount() <= value)
148                 {
149                     Log.Error(PlayerLog.Tag, "invalid index");
150                     throw new ArgumentOutOfRangeException(nameof(value), value,
151                         $"valid index range is 0 <= x < {nameof(GetCount)}(), but got { value }.");
152                 }
153
154                 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
155
156                 NativePlayer.SelectTrack(_owner.Handle, _streamType, value).
157                     ThrowIfFailed("Failed to set the selected index of the player");
158             }
159         }
160     }
161 }