Esempio n. 1
0
        private void RegisterSessionNotification(AudioSessionManager2 audioSessionManager2,
                                                 IAudioSessionNotification audioSessionNotification)
        {
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
            {
                audioSessionManager2.RegisterSessionNotification(audioSessionNotification);
            }
            else
            {
                using (ManualResetEvent waitHandle = new ManualResetEvent(false))
                {
                    ThreadPool.QueueUserWorkItem(
                        (o) =>
                    {
                        try
                        {
                            audioSessionManager2.RegisterSessionNotification(audioSessionNotification);
                        }
                        finally
                        {
// ReSharper disable once AccessToDisposedClosure
                            waitHandle.Set();
                        }
                    });
                    waitHandle.WaitOne();
                }
            }

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            audioSessionManager2.GetSessionEnumerator().ToArray(); //necessary to make it work
        }
Esempio n. 2
0
        /// <summary>
        /// Registers the application to receive a notification when a session is created.
        /// <seealso cref="RegisterSessionNotificationNative"/>
        /// </summary>
        /// <param name="sessionNotification">The application's implementation of the <see cref="IAudioSessionNotification"/> interface.</param>
        /// <returns>HRESULT</returns>
        /// <remarks>
        /// Use the <see cref="AudioSessionNotification"/> class as the default implementation for the <paramref name="sessionNotification"/> parameter.
        ///
        /// <c>Note:</c> Make sure to call the <see cref="RegisterSessionNotificationNative"/> from an MTA-Thread. Also make sure to enumerate all sessions after calling this method.
        /// </remarks>
        public unsafe int RegisterSessionNotificationNative(IAudioSessionNotification sessionNotification)
        {
            int result = 0;

            if (!_sessionNotifications.Contains(sessionNotification))
            {
                IntPtr ptr = sessionNotification != null
                    ? Marshal.GetComInterfaceForObject(sessionNotification, typeof(IAudioSessionNotification))
                    : IntPtr.Zero;

                try
                {
                    result = InteropCalls.CallI(
                        UnsafeBasePtr,
                        ptr,
                        ((void **)(*(void **)UnsafeBasePtr))[6]);
                }
                finally
                {
                    if (ptr != IntPtr.Zero)
                    {
                        Marshal.Release(ptr);
                    }
                }
                _sessionNotifications.Add(sessionNotification);
            }
            return(result);
        }
Esempio n. 3
0
 /// <summary>
 /// Registers the application to receive a notification when a session is created.
 /// </summary>
 /// <param name="sessionNotification">The application's implementation of the <see cref="IAudioSessionNotification"/> interface.</param>
 ///         /// <remarks>
 /// Use the <see cref="AudioSessionNotification"/> class as the default implementation for the <paramref name="sessionNotification"/> parameter.
 ///
 /// <c>Note:</c> Make sure to call the <see cref="RegisterSessionNotification"/> from an MTA-Thread. Also make sure to enumerate all sessions after calling this method.
 /// </remarks>
 public void RegisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
     {
         throw new InvalidOperationException("RegisterSessionNotification has to be called from an MTA-Thread.");
     }
     CoreAudioAPIException.Try(RegisterSessionNotificationNative(sessionNotification), InterfaceName,
                               "RegisterSessionNotification");
 }
Esempio n. 4
0
        /// <summary>
        /// The UnregisterSessionNotification method deletes the registration to receive a notification when a session is created.
        /// </summary>
        /// <returns>HRESULT</returns>
        public unsafe int UnregisterSessionNotificationNative(IAudioSessionNotification sessionNotification)
        {
            int result = 0;

            if (_sessionNotifications.Contains(sessionNotification))
            {
                IntPtr ptr = sessionNotification != null?Marshal.GetComInterfaceForObject(sessionNotification, typeof(IAudioSessionNotification)) : IntPtr.Zero;

                result = InteropCalls.CallI(_basePtr, (void *)ptr, ((void **)(*(void **)_basePtr))[7]);
                _sessionNotifications.Remove(sessionNotification);
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Registers the application to receive a notification when a session is created.
        /// <seealso cref="RegisterSessionNotificationNative"/>
        /// </summary>
        /// <param name="sessionNotification">The application's implementation of the <see cref="IAudioSessionNotification"/> interface.</param>
        /// <returns>HRESULT</returns>
        /// <remarks>
        /// Use the <see cref="AudioSessionNotification"/> class as the default implementation for the <paramref name="sessionNotification"/> parameter.
        ///
        /// <c>Note:</c> Make sure to call the <see cref="RegisterSessionNotificationNative"/> from an MTA-Thread. Also make sure to enumerate all sessions after calling this method.
        /// </remarks>
        public unsafe int RegisterSessionNotificationNative(IAudioSessionNotification sessionNotification)
        {
            int result = 0;

            if (!_sessionNotifications.Contains(sessionNotification))
            {
                result = InteropCalls.CallI(
                    UnsafeBasePtr,
                    sessionNotification != null
                        ? Marshal.GetComInterfaceForObject(sessionNotification, typeof(IAudioSessionNotification))
                        : IntPtr.Zero,
                    ((void **)(*(void **)UnsafeBasePtr))[6]);
                _sessionNotifications.Add(sessionNotification);
            }
            return(result);
        }
Esempio n. 6
0
 /// <summary>
 /// Deletes the registration to receive a notification when a session is created.
 /// </summary>
 /// <param name="sessionNotification">
 /// The application's implementation of the <see cref="IAudioSessionNotification"/> interface.
 /// Pass the same object that was specified to the session manager in a previous call <see cref="RegisterSessionNotification"/> to register for notification.</param>
 public void UnregisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     CoreAudioAPIException.Try(UnregisterSessionNotificationNative(sessionNotification), InterfaceName,
                               "UnregisterSessionNotification");
 }
Esempio n. 7
0
 /// <summary>
 /// Deletes the registration to receive a notification when a session is created.
 /// <seealso cref="UnregisterSessionNotification"/>
 /// </summary>
 /// <param name="sessionNotification">
 /// The application's implementation of the <see cref="IAudioSessionNotification"/> interface. 
 /// Pass the same object that was specified to the session manager in a previous call <see cref="RegisterSessionNotification"/> to register for notification.</param>
 /// <returns>HRESULT</returns>
 public unsafe int UnregisterSessionNotificationNative(IAudioSessionNotification sessionNotification)
 {
     int result = 0;
     if (_sessionNotifications.Contains(sessionNotification))
     {
         IntPtr ptr = sessionNotification != null
             ? Marshal.GetComInterfaceForObject(sessionNotification, typeof(IAudioSessionNotification))
             : IntPtr.Zero;
         try
         {
             result = InteropCalls.CallI(
                 UnsafeBasePtr,
                 ptr,
                 ((void**)(*(void**)UnsafeBasePtr))[7]);
         }
         finally
         {
             if (ptr != IntPtr.Zero)
             {
                 Marshal.Release(ptr);
             }
         }
         _sessionNotifications.Remove(sessionNotification);
     }
     return result;
 }
Esempio n. 8
0
 /// <summary>
 /// Deletes the registration to receive a notification when a session is created.
 /// </summary>
 /// <param name="sessionNotification">
 /// The application's implementation of the <see cref="IAudioSessionNotification"/> interface. 
 /// Pass the same object that was specified to the session manager in a previous call <see cref="RegisterSessionNotification"/> to register for notification.</param>
 public void UnregisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     CoreAudioAPIException.Try(UnregisterSessionNotificationNative(sessionNotification), InterfaceName,
         "UnregisterSessionNotification");
 }
Esempio n. 9
0
 /// <summary>
 /// Registers the application to receive a notification when a session is created.
 /// </summary>
 /// <param name="sessionNotification">The application's implementation of the <see cref="IAudioSessionNotification"/> interface.</param>
 ///         /// <remarks>
 /// Use the <see cref="AudioSessionNotification"/> class as the default implementation for the <paramref name="sessionNotification"/> parameter.
 /// 
 /// <c>Note:</c> Make sure to call the <see cref="RegisterSessionNotification"/> from an MTA-Thread. Also make sure to enumerate all sessions after calling this method. 
 /// </remarks>
 public void RegisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
         throw new InvalidOperationException("RegisterSessionNotification has to be called from an MTA-Thread.");
     CoreAudioAPIException.Try(RegisterSessionNotificationNative(sessionNotification), InterfaceName,
         "RegisterSessionNotification");
 }
Esempio n. 10
0
 /// <summary>
 /// The UnregisterSessionNotification method deletes the registration to receive a notification when a session is created.
 /// </summary>
 /// <returns>HRESULT</returns>
 public unsafe int UnregisterSessionNotificationNative(IAudioSessionNotification sessionNotification)
 {
     int result = 0;
     if (_sessionNotifications.Contains(sessionNotification))
     {
         IntPtr ptr = sessionNotification != null ? Marshal.GetComInterfaceForObject(sessionNotification, typeof(IAudioSessionNotification)) : IntPtr.Zero;
         result = InteropCalls.CallI(_basePtr, (void*)ptr, ((void**)(*(void**)_basePtr))[7]);
         _sessionNotifications.Remove(sessionNotification);
     }
     return result;
 }
Esempio n. 11
0
 /// <summary>
 /// The RegisterSessionNotification method registers the application to receive a notification when a session is created.
 /// </summary>
 public void RegisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     CoreAudioAPIException.Try(RegisterSessionNotificationNative(sessionNotification), c, "RegisterSessionNotification");
 }
Esempio n. 12
0
 /// <summary>
 /// The RegisterSessionNotification method registers the application to receive a notification when a session is created.
 /// </summary>
 public void RegisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     CoreAudioAPIException.Try(RegisterSessionNotificationNative(sessionNotification), c, "RegisterSessionNotification");
 }
Esempio n. 13
0
 /// <summary>
 /// Registers the application to receive a notification when a session is created.
 /// <seealso cref="RegisterSessionNotificationNative"/>
 /// </summary>
 /// <param name="sessionNotification">The application's implementation of the <see cref="IAudioSessionNotification"/> interface.</param>
 /// <returns>HRESULT</returns>
 /// <remarks>
 /// Use the <see cref="AudioSessionNotification"/> class as the default implementation for the <paramref name="sessionNotification"/> parameter.
 /// 
 /// <c>Note:</c> Make sure to call the <see cref="RegisterSessionNotificationNative"/> from an MTA-Thread. Also make sure to enumerate all sessions after calling this method. 
 /// </remarks>
 public unsafe int RegisterSessionNotificationNative(IAudioSessionNotification sessionNotification)
 {
     int result = 0;
     if (!_sessionNotifications.Contains(sessionNotification))
     {
         result = InteropCalls.CallI(
             UnsafeBasePtr,
             sessionNotification != null
                 ? Marshal.GetComInterfaceForObject(sessionNotification, typeof (IAudioSessionNotification))
                 : IntPtr.Zero,
             ((void**) (*(void**) UnsafeBasePtr))[6]);
         _sessionNotifications.Add(sessionNotification);
     }
     return result;
 }
Esempio n. 14
0
 /// <summary>
 /// Deletes the registration to receive a notification when a session is created.
 /// </summary>
 /// <param name="sessionNotification">
 /// The application's implementation of the <see cref="IAudioSessionNotification"/> interface.
 /// Pass the same object that was specified to the session manager in a previous call <see cref="RegisterSessionNotification"/> to register for notification.</param>
 public void UnregisterSessionNotification(IAudioSessionNotification sessionNotification)
 {
     UnregisterSessionNotificationNative(sessionNotification);
 }