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.
17 using System.Diagnostics;
18 using System.Runtime.InteropServices;
21 namespace Tizen.Multimedia
24 /// Provides a means to retrieve the track information.
26 /// <seealso cref="Player.SubtitleTrackInfo"/>
27 /// <seealso cref="Player.AudioTrackInfo"/>
28 /// <since_tizen> 3 </since_tizen>
29 public class PlayerTrackInfo
31 private readonly StreamType _streamType;
32 private readonly Player _owner;
34 internal PlayerTrackInfo(Player player, StreamType streamType)
36 Debug.Assert(player != null);
38 _streamType = streamType;
43 /// Gets the number of tracks.
45 /// <returns>The number of tracks.</returns>
47 /// The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
48 /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
50 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
51 /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.
53 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
55 /// <since_tizen> 3 </since_tizen>
58 _owner.ValidateNotDisposed();
59 _owner.AudioOffload.CheckDisabled();
60 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
62 NativePlayer.GetTrackCount(_owner.Handle, _streamType, out var count).
63 ThrowIfFailed(_owner, "Failed to get count of the track");
65 Log.Info(PlayerLog.Tag, "get count : " + count);
71 /// Gets the language code for the specified index, or null if the language is undefined.
73 /// <param name="index">The index of track.</param>
74 /// <returns>The number of tracks.</returns>
76 /// <para>The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
77 /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.</para>
78 /// <para>The language codes are defined in ISO 639-1.</para>
80 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
81 /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.
83 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
85 /// <exception cref="ArgumentOutOfRangeException">
86 /// <paramref name="index"/> is less than zero.<br/>
88 /// <paramref name="index"/> is equal to or greater than <see cref="GetCount()"/>.
90 /// <since_tizen> 3 </since_tizen>
91 public string GetLanguageCode(int index)
93 _owner.ValidateNotDisposed();
95 if (index < 0 || GetCount() <= index)
97 throw new ArgumentOutOfRangeException(nameof(index), index,
98 $"Valid index range is 0 <= x < {nameof(GetCount)}(), but got { index }.");
101 _owner.AudioOffload.CheckDisabled();
102 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
104 IntPtr code = IntPtr.Zero;
108 NativePlayer.GetTrackLanguageCode(_owner.Handle, _streamType, index, out code).
109 ThrowIfFailed(_owner, "Failed to get the selected language of the player");
111 string result = Marshal.PtrToStringAnsi(code);
115 Log.Error(PlayerLog.Tag, "not defined code");
118 Log.Info(PlayerLog.Tag, "get language code : " + result);
123 LibcSupport.Free(code);
128 /// Gets or sets the selected track index.
130 /// <value>The currently selected track index.</value>
132 /// The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
133 /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
135 /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
136 /// <exception cref="InvalidOperationException">
137 /// The <see cref="Player"/> that this instance belongs to is not in the valid state.<br/>
139 /// If audio offload is enabled by calling <see cref="AudioOffload.IsEnabled"/>. (Since tizen 6.0)
141 /// <exception cref="ArgumentOutOfRangeException">
142 /// <paramref name="value"/> is less than zero.<br/>
144 /// <paramref name="value"/> is equal to or greater than <see cref="GetCount()"/>.
146 /// <since_tizen> 3 </since_tizen>
151 _owner.ValidateNotDisposed();
152 _owner.AudioOffload.CheckDisabled();
153 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
155 NativePlayer.GetCurrentTrack(_owner.Handle, _streamType, out var value).
156 ThrowIfFailed(_owner, "Failed to get the selected index of the player");
157 Log.Debug(PlayerLog.Tag, "get selected index : " + value);
162 _owner.ValidateNotDisposed();
164 if (value < 0 || GetCount() <= value)
166 throw new ArgumentOutOfRangeException(nameof(value), value,
167 $"Valid index range is 0 <= x < {nameof(GetCount)}(), but got { value }.");
170 _owner.AudioOffload.CheckDisabled();
171 _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
173 NativePlayer.SelectTrack(_owner.Handle, _streamType, value).
174 ThrowIfFailed(_owner, "Failed to set the selected index of the player");