Esempio n. 1
0
            public BluetoothAudioKeeperUpper()
            {
                NCI = new NotificationClientImplementation();
                NC  = NCI;
                deviceEnum.RegisterEndpointNotificationCallback(NC);

                System.IO.Stream Sound = Properties.Res.Silence;
                Player = new SoundPlayer(Sound);
            }
Esempio n. 2
0
        public CommunicationDeviceSwitcherService()
        {
            _loggerFactory = new LoggerFactory();
            _logger        = _loggerFactory.CreateLogger <CommunicationDeviceSwitcherService>();
            var logger = _loggerFactory.CreateLogger <DefaultCommunicateDeviceSwitchNotificationClient>();

            _notificationClient = new DefaultCommunicateDeviceSwitchNotificationClient(logger);
            InitializeComponent();
        }
 public override void Enable()
 {
     _enumerator         = new MMDeviceEnumerator();
     _notificationClient = new INotificationClient();
     _notifyClient       = (IMMNotificationClient)_notificationClient;
     _notificationClient.DefaultDeviceChanged += NotificationClient_DefaultDeviceChanged;
     _enumerator.RegisterEndpointNotificationCallback(_notifyClient);
     UpdatePlaybackDevice(true);
     AddTimedUpdate(TimeSpan.FromMilliseconds(10), UpdatePeakVolume);
 }
Esempio n. 4
0
        /// <summary>
        /// Deletes the registration of a notification interface that the client registered in a previous call to the <see cref="RegisterEndpointNotificationCallback"/> method.
        /// </summary>
        /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which should be unregistered from any notifications.</param>
        /// <returns>HRESULT</returns>
        public unsafe int UnregisterEndpointNotificationCallbackNative(IMMNotificationClient notificationClient)
        {
            int result = 0;

            if (_notificationClients.Contains(notificationClient))
            {
                result = LocalInterop.Calli(UnsafeBasePtr, notificationClient, ((void **)(*(void **)UnsafeBasePtr))[7]);
                _notificationClients.Remove(notificationClient);
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Registers a client's notification callback interface.
        /// </summary>
        /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which is should receive the notificaitons.</param>
        /// <returns>HRESULT</returns>
        public unsafe int RegisterEndpointNotificationCallbackNative(IMMNotificationClient notificationClient)
        {
            int result = 0;

            if (!_notificationClients.Contains(notificationClient))
            {
                result = InteropCalls.CallI(UnsafeBasePtr, notificationClient, ((void **)(*(void **)UnsafeBasePtr))[6]);
                _notificationClients.Add(notificationClient);
            }
            return(result);
        }
Esempio n. 6
0
        public MainWindow()
        {
            InitializeComponent();
            this.StateChanged += MainWindow_StateChanged;

            DataContext = this;

            using (Stream stream = Application.GetResourceStream(new Uri("/mic.ico", UriKind.Relative)).Stream)
            {
                unmutedIcon = new Icon(stream);
            }
            using (Stream stream = Application.GetResourceStream(new Uri("/mutedmic.ico", UriKind.Relative)).Stream)
            {
                mutedIcon = new Icon(stream);
            }

            tbi.LeftClickCommand = new ShowMessageCommand(ShowWindow);

            var showUiMenuItem = new MenuItem();

            showUiMenuItem.Header = "Show UI";
            showUiMenuItem.Click += ShowUiMenuItem_Click;

            var exitMenuItem = new MenuItem();

            exitMenuItem.Header = "Exit";
            exitMenuItem.Click += ExitMenuItem_Click;

            tbi.ContextMenu = new ContextMenu();
            tbi.ContextMenu.Items.Add(showUiMenuItem);
            tbi.ContextMenu.Items.Add(exitMenuItem);

            inputDevicesComboBox.ItemsSource       = inputDeviceNames;
            inputDevicesComboBox.SelectionChanged += InputDevicesComboBox_SelectionChanged;

            notificationClient = new DeviceChangedClient(new Action(() =>
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    RefreshDeviceList("");
                }));
            }));

            var deviceEnumerator = new MMDeviceEnumerator();

            deviceEnumerator.RegisterEndpointNotificationCallback(notificationClient);

            RefreshDeviceList(Properties.Settings.Default.LastDeviceName);

            Console.WriteLine($"Selected index: {inputDevicesComboBox.SelectedIndex}");
        }
        /// <summary>
        /// Deletes the registration of a notification interface that the client registered in a previous call to the <see cref="RegisterEndpointNotificationCallback"/> method.
        /// </summary>
        /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which should be unregistered from any notifications.</param>
        /// <returns>HRESULT</returns>
        public unsafe int UnregisterEndpointNotificationCallbackNative(IMMNotificationClient notificationClient)
        {
            int result = 0;

            if (_notificationClients.Contains(notificationClient))
            {
                result = InteropCalls.CallI(UnsafeBasePtr,
                                            Marshal.GetComInterfaceForObject(notificationClient, typeof(IMMNotificationClient)),
                                            ((void **)(*(void **)UnsafeBasePtr))[7]);
                //result = InteropCalls.CallI(UnsafeBasePtr, notificationClient, ((void**)(*(void**)UnsafeBasePtr))[7]);
                _notificationClients.Remove(notificationClient);
            }
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Unregisters a call back for Device Events
        /// </summary>
        /// <param name="client">Object implementing IMMNotificationClient type casted as IMMNotificationClient interface </param>
        /// <returns></returns>
        public int UnregisterEndpointNotificationCallback([In][MarshalAs(UnmanagedType.Interface)] IMMNotificationClient client)
        {
            if (!_notificationClients.Contains(client))
            {
                return(0);
            }

            var hresult = _mmDeviceEnumerator.UnregisterEndpointNotificationCallback(client);

            Marshal.ThrowExceptionForHR(hresult);

            _notificationClients.Remove(client);
            return(hresult);
        }
Esempio n. 9
0
        private AudioInterfaceCollection()
        {
            _Context = SynchronizationContext.Current;
            _NotificationCallback = new AudioEndpointNotificationCallback(_Context);
            _NotificationClient   = (IMMNotificationClient)_NotificationCallback;

            string installDirectory = InstallPath();
            string runningDirectory = AppDomain.CurrentDomain.BaseDirectory;

            bool isInstalledVersion = installDirectory != null && runningDirectory == installDirectory;

            appdataPath = isInstalledVersion switch
            {
                true => Path.GetDirectoryName(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath) + "\\",
                false => runningDirectory
            };

            Initialise();
        }
Esempio n. 10
0
 /// <summary>
 /// Deletes the registration of a notification interface that the client registered in a previous call to the <see cref="RegisterEndpointNotificationCallback"/> method.
 /// </summary>
 /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which should be unregistered from any notifications.</param>
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient notificationClient)
 {
     CoreAudioAPIException.Try(UnregisterEndpointNotificationCallbackNative(notificationClient), InterfaceName,
                               "UnregisterEndpointNotificationCallback");
 }
 public void RegisterEndpointNotificationCallback(IMMNotificationClient pClient)
 {
     _realEnumerator.RegisterEndpointNotificationCallback(pClient);
 }
Esempio n. 12
0
 internal static unsafe int Calli(void *_basePtr, IMMNotificationClient client, void *p)
 {
     throw new NotImplementedException();
 }
Esempio n. 13
0
 public void RegisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     CoreAudioAPIException.Try(RegisterEndpointNotificationCallbackNative(client), c, "RegisterEndpointNotificationCallback");
 }
Esempio n. 14
0
        public unsafe int RegisterEndpointNotificationCallbackNative(IMMNotificationClient client)
        {
            int result = InteropCalls.CallI(_basePtr, client, ((void **)(*(void **)_basePtr))[6]);

            return(result);
        }
Esempio n. 15
0
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient pClient)
 {
     Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).UnregisterEndpointNotificationCallback(pClient));
 }
Esempio n. 16
0
 public Worker(ILogger <Worker> logger, IMMNotificationClient notificationClient)
 {
     _logger             = logger;
     _notificationClient = notificationClient;
 }
Esempio n. 17
0
 public static void RegisterEndpointNotificationCallback(IMMNotificationClient notificationClient)
 {
     _Enumerator.RegisterEndpointNotificationCallback(notificationClient);
 }
Esempio n. 18
0
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     _inner.UnregisterEndpointNotificationCallback(client);
 }
 /// <summary>
 /// Deletes the registration of a notification interface that the client registered in a previous call
 /// to the <see cref="IMMDeviceEnumerator.RegisterEndpointNotificationCallback"/> method.
 /// </summary>
 /// <param name="client">A <see cref="IMMNotificationClient"/> interface that was previously registered for notification callbacks.</param>
 /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     Marshal.ThrowExceptionForHR(_realEnumerator.UnregisterEndpointNotificationCallback(client));
 }
Esempio n. 20
0
 /// <summary>
 /// Registers a call back for Device Events
 /// </summary>
 /// <param name="client">Object implementing IMMNotificationClient type casted as IMMNotificationClient interface</param>
 /// <returns></returns>
 private int RegisterEndpointNotificationCallback([In][MarshalAs(UnmanagedType.Interface)] IMMNotificationClient client)
 {
     return(_enumerator.RegisterEndpointNotificationCallback(client));
 }
Esempio n. 21
0
 public int RegisterEndpointNotificationCallback([MarshalAs(UnmanagedType.Interface)][In] IMMNotificationClient client)
 {
     return(this.realEnumerator.RegisterEndpointNotificationCallback(client));
 }
Esempio n. 22
0
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     _inner.UnregisterEndpointNotificationCallback(client);
 }
Esempio n. 23
0
 public unsafe int UnregisterEndpointNotificationCallbackNative(IMMNotificationClient client)
 {
     return(InteropCalls.CallI(_basePtr, client, ((void **)(*(void **)_basePtr))[7]));
 }
Esempio n. 24
0
 /// <summary>
 /// Deletes the registration of a notification interface that the client registered in a previous call to the <see cref="RegisterEndpointNotificationCallback"/> method.
 /// </summary>
 /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which should be unregistered from any notifications.</param>
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient notificationClient)
 {
     CoreAudioAPIException.Try(UnregisterEndpointNotificationCallbackNative(notificationClient), InterfaceName,
         "UnregisterEndpointNotificationCallback");
 }
Esempio n. 25
0
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     CoreAudioAPIException.Try(UnregisterEndpointNotificationCallbackNative(client), c, "UnregisterEndpointNotificationCallback");
 }
Esempio n. 26
0
 /// <summary>
 /// Deletes the registration of a notification interface that the client registered in a previous call
 /// to the <see cref="IMMDeviceEnumerator.RegisterEndpointNotificationCallback"/> method.
 /// </summary>
 /// <param name="client">A <see cref="IMMNotificationClient"/> interface that was previously registered for notification callbacks.</param>
 /// <returns>An HRESULT code indicating whether the operation passed of failed.</returns>
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     Marshal.ThrowExceptionForHR(_realEnumerator.UnregisterEndpointNotificationCallback(client));
 }
Esempio n. 27
0
 internal static unsafe int CallI(void* _basePtr, IMMNotificationClient client, void* p)
 {
     throw new NotImplementedException();
 }
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     _realEnumerator.UnregisterEndpointNotificationCallback(client);
 }
Esempio n. 29
0
 /// <summary>
 /// Registers a client's notification callback interface.
 /// </summary>
 /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which is should receive the notificaitons.</param>
 /// <returns>HRESULT</returns>
 public unsafe int RegisterEndpointNotificationCallbackNative(IMMNotificationClient notificationClient)
 {
     int result = InteropCalls.CallI(UnsafeBasePtr, notificationClient, ((void**) (*(void**) UnsafeBasePtr))[6]);
     return result;
 }
Esempio n. 30
0
 public void RegisterEndpointNotificationCallback(IMMNotificationClient pClient)
 {
     _realEnumerator.RegisterEndpointNotificationCallback(pClient);
 }
Esempio n. 31
0
 /// <summary>
 /// Deletes the registration of a notification interface that the client registered in a previous call to the <see cref="RegisterEndpointNotificationCallback"/> method.
 /// </summary>
 /// <param name="notificationClient">Implementation of the <see cref="IMMNotificationClient"/> which should be unregistered from any notifications.</param>
 /// <returns>HRESULT</returns>
 public unsafe int UnregisterEndpointNotificationCallbackNative(IMMNotificationClient notificationClient)
 {
     return InteropCalls.CallI(UnsafeBasePtr, notificationClient, ((void**) (*(void**) UnsafeBasePtr))[7]);
 }
 public void UnregisterEndpointNotificationCallback(IMMNotificationClient client)
 {
     _realEnumerator.UnregisterEndpointNotificationCallback(client);
 }
 /// <summary>
 /// Unregisters a call back for Device Events
 /// </summary>
 /// <param name="client">Object implementing IMMNotificationClient type casted as IMMNotificationClient interface </param>
 /// <returns></returns>
 public int UnregisterEndpointNotificationCallback(
     [In][MarshalAs(UnmanagedType.Interface)] IMMNotificationClient client)
 {
     return(realEnumerator.UnregisterEndpointNotificationCallback(client));
 }
Esempio n. 34
0
        public static void RegisterCallback(IMMNotificationClient notificationClient)
        {
            var devEnm = new MMDeviceEnumerator();

            devEnm.RegisterEndpointNotificationCallback(notificationClient);
        }