Ejemplo n.º 1
0
        private void Timer_UpdatePeakValue(long ticks)
        {
            if (_isUpdatingPeakValue || AudioMeterInformation == null)
            {
                return;
            }

            _isUpdatingPeakValue = true;

            var peakValue = _peakValue;

            if (_isDisposed)
            {
                return;
            }

            try
            {
                AudioMeterInformation.GetPeakValue(out peakValue);
            }
            catch
            {
                //ignored - usually means the com object has been released, but the timer is still ticking
            }

            if (Math.Abs(_peakValue - peakValue) > 0.001)
            {
                _peakValue = peakValue;
                OnPeakValueChanged(peakValue * 100);
            }

            _isUpdatingPeakValue = false;
        }
Ejemplo n.º 2
0
        private void LoadAudioMeterInformation(IMMDevice device)
        {
            //This should be all on the COM thread to avoid any
            //weird lookups on the result COM object not on an STA Thread
            ComThread.Assert();

            object    result = null;
            Exception ex;

            //Need to catch here, as there is a chance that unauthorized is thrown.
            //It's not an HR exception, but bubbles up through the .net call stack
            try
            {
                var clsGuid = new Guid(ComIIds.AUDIO_METER_INFORMATION_IID);
                ex = Marshal.GetExceptionForHR(device.Activate(ref clsGuid, ClsCtx.Inproc, IntPtr.Zero, out result));
            }
            catch (Exception e)
            {
                ex = e;
            }

            if (ex != null)
            {
                ClearAudioMeterInformation();
                return;
            }

            _audioMeterInformation = new AudioMeterInformation(result as IAudioMeterInformation);
        }
Ejemplo n.º 3
0
 private void ClearAudioMeterInformation()
 {
     if (_audioMeterInformation != null)
     {
         _audioMeterInformation.Dispose();
         _audioMeterInformation = null;
     }
 }
        private void LoadAudioMeterInformation(IMMDevice device)
        {
            //This should be all on the COM thread to avoid any
            //weird lookups on the result COM object not on an STA Thread
            ComThread.Assert();

            object result = null;
            Exception ex;
            //Need to catch here, as there is a chance that unauthorized is thrown.
            //It's not an HR exception, but bubbles up through the .net call stack
            try
            {
                var clsGuid = new Guid(ComIIds.AUDIO_METER_INFORMATION_IID);
                ex = Marshal.GetExceptionForHR(device.Activate(ref clsGuid, ClsCtx.Inproc, IntPtr.Zero, out result));
            }
            catch (Exception e)
            {
                ex = e;
            }

            if (ex != null)
            {
                ClearAudioMeterInformation();
                return;
            }

            _audioMeterInformation = new AudioMeterInformation(result as IAudioMeterInformation);
        }
 private void ClearAudioMeterInformation()
 {
     if (_audioMeterInformation != null)
     {
         _audioMeterInformation.Dispose();
         _audioMeterInformation = null;
     }
 }