-/*
+/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
private readonly int _id;
private readonly AudioDeviceType _type;
private readonly AudioDeviceIoDirection _ioDirection;
+ private readonly IntPtr _deviceHandle;
internal AudioDevice(IntPtr deviceHandle)
{
ret = Interop.AudioDevice.GetDeviceIoDirection(deviceHandle, out _ioDirection);
MultimediaDebug.AssertNoError(ret);
+
+ _deviceHandle = deviceHandle;
}
/// <summary>
/// </summary>
/// <value>The <see cref="AudioDeviceState"/> of the device.</value>
/// <since_tizen> 3 </since_tizen>
+ [Obsolete("Deprecated since API level 5. Please use the IsRunning property instead.")]
public AudioDeviceState State
{
get
}
}
+ /// <summary>
+ /// Gets the running state of the device.
+ /// </summary>
+ /// <value>true if the audio stream of device is running actually; otherwise, false.</value>
+ /// <since_tizen> 5 </since_tizen>
+ public bool IsRunning
+ {
+ get
+ {
+ Interop.AudioDevice.IsDeviceRunning(_deviceHandle, out bool isRunning).
+ ThrowIfError("Failed to get the running state of the device");
+
+ return isRunning;
+ }
+ }
+
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
--- /dev/null
+/*
+ * Copyright (c) 2018 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;
+
+namespace Tizen.Multimedia
+{
+ /// <summary>
+ /// Provides data for the <see cref="AudioManager.DeviceRunningChanged"/> event.
+ /// </summary>
+ /// <since_tizen> 5 </since_tizen>
+ public class AudioDeviceRunningChangedEventArgs : EventArgs
+ {
+ internal AudioDeviceRunningChangedEventArgs(AudioDevice device, bool isRunning)
+ {
+ Device = device;
+ IsRunning = isRunning;
+ }
+
+ /// <summary>
+ /// Gets the device.
+ /// </summary>
+ /// <value>The <see cref="AudioDevice"/>.</value>
+ /// <since_tizen> 5 </since_tizen>
+ public AudioDevice Device { get; }
+
+ /// <summary>
+ /// Gets the running state of the device.
+ /// </summary>
+ /// <value>true if the audio stream of device is running actually; otherwise, false.</value>
+ /// <since_tizen> 5 </since_tizen>
+ public bool IsRunning { get; }
+ }
+}
\ No newline at end of file
/// Provides data for the <see cref="AudioManager.DeviceStateChanged"/> event.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Obsolete("Deprecated since API level 5. Please use the AudioDeviceRunningChangedEventArgs class instead.")]
public class AudioDeviceStateChangedEventArgs : EventArgs
{
internal AudioDeviceStateChangedEventArgs(AudioDevice device, AudioDeviceState changedState)
-/*
+/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
/// Occurs when the state of an audio device changes.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Obsolete("Deprecated since API level 5. Please use the DeviceRunningStateChanged property instead.")]
public static event EventHandler<AudioDeviceStateChangedEventArgs> DeviceStateChanged
{
add
ThrowIfError("Failed to remove device state changed event");
}
#endregion
+
+ #region DeviceRunningStateChanged event
+ private static int _deviceRunningChangedCallbackId = -1;
+ private static Interop.AudioDevice.RunningChangedCallback _audioDeviceRunningChangedCallback;
+ private static EventHandler<AudioDeviceRunningChangedEventArgs> _audioDeviceRunningChanged;
+ private static readonly object _audioDeviceRunningLock = new object();
+
+ /// <summary>
+ /// Occurs when the audio stream started actually to running on device.
+ /// </summary>
+ /// <remarks>
+ /// If this event is invoked once and audio stream is still running on device,<br/>
+ /// it will not invoked any more even if more audio stream runs again,<br/>
+ /// until all streams are stoped and another stream runs again.
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">
+ /// AudioManager failed to communicate internally or allocate memory.
+ /// </exception>
+ /// <since_tizen> 5 </since_tizen>
+ public static event EventHandler<AudioDeviceRunningChangedEventArgs> DeviceRunningChanged
+ {
+ add
+ {
+ if (value == null)
+ {
+ return;
+ }
+ lock (_audioDeviceRunningLock)
+ {
+ if (_audioDeviceRunningChanged == null)
+ {
+ RegisterDeviceRunningChangedEvent();
+ }
+ _audioDeviceRunningChanged += value;
+ }
+ }
+ remove
+ {
+ if (value == null)
+ {
+ return;
+ }
+ lock (_audioDeviceRunningLock)
+ {
+ _audioDeviceRunningChanged -= value;
+ if (_audioDeviceRunningChanged == null)
+ {
+ UnregisterDeviceRunningChangedEvent();
+ }
+ }
+ }
+ }
+
+ private static void RegisterDeviceRunningChangedEvent()
+ {
+ _audioDeviceRunningChangedCallback = (device, isRunning, _) =>
+ {
+ _audioDeviceRunningChanged?.Invoke(null,
+ new AudioDeviceRunningChangedEventArgs(new AudioDevice(device), isRunning));
+ };
+ Interop.AudioDevice.AddDeviceRunningChangedCallback(AudioDeviceOptions.All,
+ _audioDeviceRunningChangedCallback, IntPtr.Zero, out _deviceRunningChangedCallbackId).
+ ThrowIfError("Failed to add DeviceRunningChanged event");
+ }
+
+ private static void UnregisterDeviceRunningChangedEvent()
+ {
+ Interop.AudioDevice.RemoveDeviceRunningChangedCallback(_deviceRunningChangedCallbackId).
+ ThrowIfError("Failed to remove DeviceRunningChanged event");
+ }
+ #endregion
}
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void StateChangedCallback(IntPtr device, AudioDeviceState changedState, IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void RunningChangedCallback(IntPtr device, bool isRunning, IntPtr userData);
+
+
[DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_list")]
internal static extern AudioManagerError GetDeviceList(AudioDeviceOptions deviceMask, out IntPtr deviceList);
[DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_get_device_state_by_id")]
internal static extern AudioManagerError GetDeviceState(int deviceId, out AudioDeviceState state);
+ [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_is_device_running")]
+ internal static extern AudioManagerError IsDeviceRunning(IntPtr device, out bool isRunning);
+
[DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_connection_changed_cb")]
internal static extern AudioManagerError AddDeviceConnectionChangedCallback(
AudioDeviceOptions deviceMask, ConnectionChangedCallback callback, IntPtr userData, out int id);
[DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_state_changed_cb")]
internal static extern AudioManagerError RemoveDeviceStateChangedCallback(int id);
+
+ [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_add_device_running_changed_cb")]
+ internal static extern AudioManagerError AddDeviceRunningChangedCallback(AudioDeviceOptions deviceMask,
+ RunningChangedCallback callback, IntPtr userData, out int id);
+
+ [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_device_running_changed_cb")]
+ internal static extern AudioManagerError RemoveDeviceRunningChangedCallback(int id);
}
}
}