0

This is in continuation of this question: Getting individual windows application current volume output level as visualized in audio Mixer

How to register an EventHandler which gets called whenever the current output volume of an application (such as windows media player) changes? In other words, how to register an EventHandler which gets called whenever GetPeakValue of an AudioSessionControl changes?

For my application I want it such that whenever the PeakValue of Windows Media Player changes, a function should get called, instead of me continuously polling for the current PeakValue to identify if there is a change or not.

I am using CSCore.CoreAudioAPI to get the current audio value of any application. I tried using AudioSessionEvents (and its event handlers like SimpleVolumeChanged, ChannelVolumeChanged) in CSCore, however I did not find any way to pass an AudioSessionControl object to attached the handlers with.

Community
  • 1
  • 1
mio
  • 159
  • 1
  • 1
  • 11
  • There is no event for the peak. Just for the volume you can set itself. But not for the current peak. You have to use a timer, loop,... – Florian Mar 08 '14 at 14:53
  • Thanks @thefiloe for clarifying that. Using a loop in a separate thread (with sleep) throws this error: "The calling thread cannot access this object because a different thread owns it" as I am trying to bind the peak volume value to some visualization on the UI thread. Any work around? – mio Mar 08 '14 at 16:10
  • Are you updating the ui directly from the seperate thread? You can't access the UI from another thread. You need to invoke the control by calling `myControl.Invoke(() => {textBox.Text = "Hello World";});` – Florian Mar 08 '14 at 20:41
  • Yes that I know. I am using a custom control (UserControl in WPF), and the control UI gets updated with data Binding, due to which I am not able to call myControl.Invoke() on it. Basically I am trying to use this code http://channel9.msdn.com/coding4fun/articles/NET-Voice-Recorder to show the waveform visualization of peak volume level of an application. – mio Mar 11 '14 at 18:16

0 Answers0