using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace Tizen.Multimedia
{
private static int _focusStateWatchCounter = 0;
private static EventHandler<FocusStateChangedEventArgs> _focusStateWatchForPlayback;
- private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchForPlaybackCallback;
+ private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchCallback;
private static EventHandler<FocusStateChangedEventArgs> _focusStateWatchForRecording;
- private static Interop.SoundStreamFocusStateWatchCallback _focusStateWatchForRecordingCallback;
private EventHandler<StreamFocusStateChangedEventArgs> _focusStateChanged;
private Interop.SoundStreamFocusStateChangedCallback _focusStateChangedCallback;
-
-
+\r
/// <summary>
/// Auto focus reacquisition property
/// </summary>
_streamType = streamType;
_focusStateChangedCallback = (IntPtr streamInfo, int reason, string extraInfo, IntPtr userData) =>
{
- //_focusStateChangedEventArgs = new FocusStateChangedEventArgs(reason, extraInfo);
- // _focusStateChanged.Invoke(this, _focusStateChangedEventArgs);
+ StreamFocusStateChangedEventArgs eventArgs = new StreamFocusStateChangedEventArgs((AudioStreamFocusChangedReason)reason, extraInfo);
+ _focusStateChanged?.Invoke(this, eventArgs);
};
int ret = Interop.StreamPolicy.CreateStreamInformation((int)streamType, _focusStateChangedCallback, IntPtr.Zero, out _streamInfo);
/// Acquires the stream focus.
/// </summary>
/// <param name="focusMask">The focus mask that user wants to acquire</param>
- /// <param name="?">he Extra information for this request (optional, this can be null)</param>
+ /// <param name="extraInformation">The Extra information for this request (optional, this can be null)</param>
/// <remarks>
/// Do not call this API within event handlers of FocuStateChanged and StreamFocusStateWatch else it will throw and exception
/// </remarks>
{
add
{
- if (AudioStreamPolicy._focusStateWatchForPlayback == null)
+ if (_focusStateWatchCounter == 0)
{
- RegisterPlaybackFocusStateWatchEvent();
+ RegisterFocusStateWatchEvent();
}
_focusStateWatchCounter++;
- AudioStreamPolicy._focusStateWatchForPlayback += value;
+ _focusStateWatchForPlayback += value;
}
remove
{
- AudioStreamPolicy._focusStateWatchForPlayback -= value;
+ _focusStateWatchForPlayback -= value;
_focusStateWatchCounter--;
- if (AudioStreamPolicy._focusStateWatchForPlayback == null && _focusStateWatchCounter == 0)
+ if (_focusStateWatchCounter == 0)
{
- UnregisterFocusStateWatchForPlaybackEvent();
+ UnregisterFocusStateWatch();
}
-
}
- }
-
- private static void RegisterPlaybackFocusStateWatchEvent()
- {
- AudioStreamPolicy._focusStateWatchForPlaybackCallback = (AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) =>
- {
- FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(options, focusState, reason, extraInfo);
- AudioStreamPolicy._focusStateWatchForPlayback.Invoke(null, eventArgs);
- };
- int ret = Interop.StreamPolicy.SetFocusStateWatchCallback(AudioStreamFocusOptions.Playback, AudioStreamPolicy._focusStateWatchForPlaybackCallback, IntPtr.Zero);
- AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback for playback");
- }
-
- private static void UnregisterFocusStateWatchForPlaybackEvent()
- {
- int ret = Interop.StreamPolicy.UnsetFocusStateWatchCallback();
- AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback for playback");
- }
-
+ }\r
+\r
/// <summary>
/// Registers the watch function to be invoked when the focus state for each sound stream type is changed regardless of the process.
/// <remarks>
{
add
{
- if (AudioStreamPolicy._focusStateWatchForRecording == null)
+ if (_focusStateWatchCounter == 0)
{
- RegisterRecordingFocusStateWatchEvent();
+ RegisterFocusStateWatchEvent();
}
_focusStateWatchCounter++;
- AudioStreamPolicy._focusStateWatchForRecording += value;
+ _focusStateWatchForRecording += value;
}
remove
{
- AudioStreamPolicy._focusStateWatchForRecording -= value;
+ _focusStateWatchForRecording -= value;
_focusStateWatchCounter--;
- if (AudioStreamPolicy._focusStateWatchForRecording == null && _focusStateWatchCounter == 0)
+ if (_focusStateWatchCounter == 0)
{
- UnregisterFocusStateWatchForRecordingEvent();
+ UnregisterFocusStateWatch();
}
-
}
}
- private static void RegisterRecordingFocusStateWatchEvent()
+ private static void RegisterFocusStateWatchEvent()
{
- AudioStreamPolicy._focusStateWatchForRecordingCallback = (AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) =>
- {
- FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(options, focusState, reason, extraInfo);
- AudioStreamPolicy._focusStateWatchForRecording.Invoke(null, eventArgs);
- };
- int ret = Interop.StreamPolicy.SetFocusStateWatchCallback(AudioStreamFocusOptions.Recording, AudioStreamPolicy._focusStateWatchForRecordingCallback, IntPtr.Zero);
- AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback for recording");
+ _focusStateWatchCallback = (AudioStreamFocusOptions options, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInfo, IntPtr userData) =>
+ {
+ FocusStateChangedEventArgs eventArgs = new FocusStateChangedEventArgs(focusState, reason, extraInfo);
+ if (options == AudioStreamFocusOptions.Playback)\r
+ {\r
+ _focusStateWatchForPlayback?.Invoke(null, eventArgs);\r
+ }
+ else if (options == AudioStreamFocusOptions.Recording)\r
+ {\r
+ _focusStateWatchForRecording?.Invoke(null, eventArgs);\r
+ }\r
+ else if (options == (AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording))\r
+ {\r
+ _focusStateWatchForPlayback?.Invoke(null, eventArgs);\r
+ _focusStateWatchForRecording?.Invoke(null, eventArgs);\r
+ }
+ };
+ int ret = Interop.StreamPolicy.SetFocusStateWatchCallback(AudioStreamFocusOptions.Playback | AudioStreamFocusOptions.Recording, _focusStateWatchCallback, IntPtr.Zero);
+ AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to set focus state watch callback");
}
- private static void UnregisterFocusStateWatchForRecordingEvent()
+ private static void UnregisterFocusStateWatch()
{
- int ret = Interop.StreamPolicy.UnsetFocusStateWatchCallback();
- AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback for recording");
+ int ret = Interop.StreamPolicy.UnsetFocusStateWatchCallback();\r
+ AudioManagerErrorFactory.CheckAndThrowException(ret, "Unable to unset focus state watch callback");
}
/// <summary>
{
add
{
- if (_focusStateChanged == null)
- {
- RegisterFocusStateChangedEvent();
- }
_focusStateChanged += value;
}
remove
{
_focusStateChanged -= value;
-
}
-
- }
-
- public void RegisterFocusStateChangedEvent()
- {
- _focusStateChangedCallback = (IntPtr streamInfo, int reason, string extraInfo, IntPtr userData) =>
- {
- StreamFocusStateChangedEventArgs eventArgs = new StreamFocusStateChangedEventArgs((AudioStreamFocusChangedReason)reason, extraInfo);
- _focusStateChanged.Invoke(this, eventArgs);
- };
-
}
-
-
~AudioStreamPolicy()
{
Dispose(false);
using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
\r
namespace Tizen.Multimedia\r
{\r
/// </summary>\r
public class FocusStateChangedEventArgs : EventArgs\r
{\r
- private AudioStreamFocusOptions _focusMask;\r
private AudioStreamFocusState _focusState;\r
private AudioStreamFocusChangedReason _reason;\r
private string _extraInformation;\r
\r
- internal FocusStateChangedEventArgs(AudioStreamFocusOptions focusMask, AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation)\r
+ internal FocusStateChangedEventArgs(AudioStreamFocusState focusState, AudioStreamFocusChangedReason reason, string extraInformation)\r
{\r
- _focusMask = focusMask;\r
_focusState = focusState;\r
_reason = reason;\r
_extraInformation = extraInformation;\r
}\r
\r
/// <summary>\r
- /// The changed focus mask\r
+ /// The changed focus state\r
/// </summary>\r
- public AudioStreamFocusOptions FocusMask\r
+ public AudioStreamFocusState FocusState \r
{\r
get\r
{\r
- return _focusMask;\r
+ return _focusState;\r
}\r
-\r
}\r
\r
/// <summary>\r
- /// The changed focus state\r
+ /// The reason for state change of the focus\r
/// </summary>\r
- public AudioStreamFocusState FocusState \r
+ public AudioStreamFocusChangedReason FocusChangedReason \r
{\r
get\r
{\r
- return _focusState;\r
+ return _reason;\r
}\r
}\r
\r
/// <summary>\r
- /// The reason for state change of the focus\r
+ /// The extra information\r
/// </summary>\r
- public AudioStreamFocusChangedReason FocusChangedReason \r
+ public string ExtraInformation\r
{\r
get\r
{\r
- return _reason;\r
+ return _extraInformation;\r
}\r
}\r
}\r