// ----------------------------------------- // milligan22963 - implemented to work with nAudio // 12/2014 // ----------------------------------------- using System; using System.Runtime.InteropServices; using NAudio.CoreAudioApi.Interfaces; namespace NAudio.CoreAudioApi { /// /// AudioSessionEvents callback implementation /// public class AudioSessionEventsCallback : IAudioSessionEvents { private readonly IAudioSessionEventsHandler audioSessionEventsHandler; /// /// Constructor. /// /// public AudioSessionEventsCallback(IAudioSessionEventsHandler handler) { audioSessionEventsHandler = handler; } /// /// Notifies the client that the display name for the session has changed. /// /// The new display name for the session. /// A user context value that is passed to the notification callback. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnDisplayNameChanged( [In] [MarshalAs(UnmanagedType.LPWStr)] string displayName, [In] ref Guid eventContext) { audioSessionEventsHandler.OnDisplayNameChanged(displayName); return 0; } /// /// Notifies the client that the display icon for the session has changed. /// /// The path for the new display icon for the session. /// A user context value that is passed to the notification callback. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnIconPathChanged( [In] [MarshalAs(UnmanagedType.LPWStr)] string iconPath, [In] ref Guid eventContext) { audioSessionEventsHandler.OnIconPathChanged(iconPath); return 0; } /// /// Notifies the client that the volume level or muting state of the session has changed. /// /// The new volume level for the audio session. /// The new muting state. /// A user context value that is passed to the notification callback. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnSimpleVolumeChanged( [In] [MarshalAs(UnmanagedType.R4)] float volume, [In] [MarshalAs(UnmanagedType.Bool)] bool isMuted, [In] ref Guid eventContext) { audioSessionEventsHandler.OnVolumeChanged(volume, isMuted); return 0; } /// /// Notifies the client that the volume level of an audio channel in the session submix has changed. /// /// The channel count. /// An array of volumnes cooresponding with each channel index. /// The number of the channel whose volume level changed. /// A user context value that is passed to the notification callback. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnChannelVolumeChanged( [In] [MarshalAs(UnmanagedType.U4)] UInt32 channelCount, [In] [MarshalAs(UnmanagedType.SysInt)] IntPtr newVolumes, // Pointer to float array [In] [MarshalAs(UnmanagedType.U4)] UInt32 channelIndex, [In] ref Guid eventContext) { audioSessionEventsHandler.OnChannelVolumeChanged(channelCount, newVolumes, channelIndex); return 0; } /// /// Notifies the client that the grouping parameter for the session has changed. /// /// The new grouping parameter for the session. /// A user context value that is passed to the notification callback. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnGroupingParamChanged( [In] ref Guid groupingId, [In] ref Guid eventContext) { audioSessionEventsHandler.OnGroupingParamChanged(ref groupingId); return 0; } /// /// Notifies the client that the stream-activity state of the session has changed. /// /// The new session state. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnStateChanged( [In] AudioSessionState state) { audioSessionEventsHandler.OnStateChanged(state); return 0; } /// /// Notifies the client that the session has been disconnected. /// /// The reason that the audio session was disconnected. /// An HRESULT code indicating whether the operation succeeded of failed. public int OnSessionDisconnected( [In] AudioSessionDisconnectReason disconnectReason) { audioSessionEventsHandler.OnSessionDisconnected(disconnectReason); return 0; } } }