示例#1
0
        public VolumeControl()
        {
            var defaultAudioRenderDevice = MediaDevice.GetDefaultAudioRenderId(AudioDeviceRole.Default);
            var activateAudioInterfaceCompletionHandler = new ActivateAudioInterfaceCompletionHandler <IAudioEndpointVolume>();

            IActivateAudioInterfaceAsyncOperation activateOperation;
            var hr = ActivateAudioInterfaceAsync(defaultAudioRenderDevice, typeof(IAudioEndpointVolume).GetTypeInfo().GUID, IntPtr.Zero, (IActivateAudioInterfaceCompletionHandler)activateAudioInterfaceCompletionHandler, out activateOperation);

            Debug.Assert(hr == HResult.S_OK);

            _audioEndpointVolume = GetAudioEndpointVolumeInterface();

            Debug.Assert(_audioEndpointVolume != null);
        }
示例#2
0
        private static IAudioEndpointVolume GetAudioEndpointVolumeInterface()

        {
            var speakerId = MediaDevice.GetDefaultAudioRenderId(AudioDeviceRole.Default);

            var completionHandler = new ActivateAudioInterfaceCompletionHandler <IAudioEndpointVolume>();

            var hr = ActivateAudioInterfaceAsync(
                speakerId,
                typeof(IAudioEndpointVolume).GetTypeInfo().GUID,
                IntPtr.Zero,
                completionHandler,
                out var activateOperation);

            Debug.Assert(hr == (uint)HResult.S_OK);

            return(completionHandler.WaitForCompletion());
        }