/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Diagnostics; using System.Runtime.InteropServices; using static Interop; namespace Tizen.Multimedia { /// /// Provides a means to retrieve the track information. /// /// /// public class PlayerTrackInfo { private readonly int _streamType; private readonly Player _owner; internal PlayerTrackInfo(Player player, StreamType streamType) { Debug.Assert(player != null); Log.Debug(PlayerLog.Tag, "streamType : " + streamType); _streamType = (int)streamType; _owner = player; } /// /// Gets the number of tracks. /// /// The number of tracks. /// /// The that owns this instance must be in the , /// , or state. /// /// The that this instance belongs to has been disposed of. /// The that this instance belongs to is not in the valid state. public int GetCount() { _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused); int count = 0; NativePlayer.GetTrackCount(_owner.Handle, _streamType, out count). ThrowIfFailed("Failed to get count of the track"); Log.Info(PlayerLog.Tag, "get count : " + count); return count; } /// /// Gets the language code for the specified index, or null if the language is undefined. /// /// The number of tracks. /// /// The that owns this instance must be in the , /// , or state. /// The language codes are defined in ISO 639-1. /// /// The that this instance belongs to has been disposed of. /// The that this instance belongs to is not in the valid state. /// /// is less than zero.
/// -or-
/// is equal to or greater than ///
public string GetLanguageCode(int index) { _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused); if (index < 0 || GetCount() <= index) { Log.Error(PlayerLog.Tag, "invalid index"); throw new ArgumentOutOfRangeException(nameof(index), index, $"valid index range is 0 <= x < {nameof(GetCount)}(), but got { index }."); } IntPtr code = IntPtr.Zero; try { NativePlayer.GetTrackLanguageCode(_owner.Handle, _streamType, index, out code). ThrowIfFailed("Failed to get the selected language of the player"); string result = Marshal.PtrToStringAnsi(code); if (result == "und") { Log.Error(PlayerLog.Tag, "not defined code"); return null; } Log.Info(PlayerLog.Tag, "get language code : " + result); return result; } finally { LibcSupport.Free(code); } } /// /// Gets or sets the selected track index. /// /// The currently selected track index. /// /// The that owns this instance must be in the , /// , or state. /// /// The that this instance belongs to has been disposed of. /// The that this instance belongs to is not in the valid state. /// /// is less than zero.
/// -or-
/// is equal to or greater than ///
public int Selected { get { _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused); int value = 0; NativePlayer.GetCurrentTrack(_owner.Handle, _streamType, out value). ThrowIfFailed("Failed to get the selected index of the player"); Log.Debug(PlayerLog.Tag, "get selected index : " + value); return value; } set { if (value < 0 || GetCount() <= value) { Log.Error(PlayerLog.Tag, "invalid index"); throw new ArgumentOutOfRangeException(nameof(value), value, $"valid index range is 0 <= x < {nameof(GetCount)}(), but got { value }."); } _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused); NativePlayer.SelectTrack(_owner.Handle, _streamType, value). ThrowIfFailed("Failed to set the selected index of the player"); } } } }