2

I monitor the input volume in the computer (i.e the volume in the computer's mixer, not the system volume/the output volume) in C# using the NAudio library:

inputVolume = device.AudioMeterInformation.MasterPeakValue;

Now, the input volume also depends on the software/media player that plays the audio - either Windows Media Player, the WMP browser plugin or any other software (like VLC, Winamp, Quciktime, etc).

My problem is that I need to know when the user changes the input volume through the software that plays the audio. When a user increases the volume level in the software, for example, it increases the input volume - but I can't know if it's because the stream itself is "louder" or because the user has increased the volume level in the software that plays the audio.

If the user just increases the computer system volume, it doesn't affect anything, because it's the output volume and I don't care about it.

The audio is not from a file on the user computer but rather from a live stream through the internet (it can still be played on audio applications that are installed on the computer and not only in the browser).

Is it possible to get the volume level in the software that plays the audio? It's usually the Windows Media Player browser plugin, but it can also be a different software.
If it's not possible, is there any workaround?

amiregelz
  • 1,833
  • 7
  • 25
  • 46
  • http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c-sharp – m4ngl3r Oct 29 '13 at 10:40
  • @m4ngl3r I only need the volume level in the volume bar which is inside the player that plays the audio in the computer. Does this mean I have to play the audio through C#? Would that even help? I don't think so.. – amiregelz Oct 29 '13 at 12:35
  • Does the software playing the audio offer an API? Your best bet if to stream the audio through your own software. – user2140261 Oct 29 '13 at 16:18
  • @user2140261 It's almost always WMP browser plugin, but I wasn't sure if I can use any Windows Media Player API with C# since it's playing in the browser. – amiregelz Oct 29 '13 at 16:22
  • It means, use the Volume property on WaveChannel32 instead. Also, unless you are using an old version of NAudio, the BlockAlignReductionStream and the WaveFormatConversion stream are unneccessary, since MP3FileReader emits PCM. – m4ngl3r Oct 30 '13 at 05:43
  • @m4ngl3r Thanks for the response, can you give me some more guidance on how to use it? Can you write it as an answer? I'm not experienced with NAudio at all..Thank you – amiregelz Oct 30 '13 at 09:33

1 Answers1

0
var player = new WaveOut();
var file = new AudioFileReader(@"test.mp3");
var meter = new MeteringSampleProvider(file);
meter.StreamVolume += (s,e) => Console.WriteLine("{0} - {1}", e.MaxSampleValues[0],e.MaxSampleValues[1]);
player.Init(new SampleToWaveProvider(meter));

var form = new Form();
form.Load += (s,e) => player.Play();
form.FormClosed += (s,e) => player.Dispose();
form.ShowDialog();

Some useful links

SO Question

So Question

Community
  • 1
  • 1
Sakthivel
  • 1,890
  • 2
  • 21
  • 47
  • I should have mentioned, the audio is not from a file that is on the computer - it's from a live stream through the internet. Is that a problem? – amiregelz Oct 20 '13 at 09:05
  • Then you should get the streams, wait i just found some article like that. ll give you the link. – Sakthivel Oct 20 '13 at 09:23
  • This isn't helpful in my case. – amiregelz Oct 25 '13 at 12:44
  • http://stackoverflow.com/questions/3992798/how-to-programmatically-get-the-current-audio-level – Sakthivel Oct 25 '13 at 14:05
  • It's irrelevant, I already have the audio stream level in the mixer, but I need the audio level in the *software that plays the audio*, not in the computer mixer. – amiregelz Oct 25 '13 at 15:13