|
|
Hi,
I have created player using NAudio and now I have to add VOLUME METER. I use the following code.
WaveOut Player = new WaveOut();
string fileName;
AudioFileReader FileReader;
FileReader = new AudioFileReader(fileName);
Player.Init(FileReader);
Player.Play();
How I add volume meter to my player... from where I get value for Volume meter..
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 6, 2012 at 1:06 PM
|
hi, have a look at the Audio File Playback code in the NAudioDemo project. This shows how to create a volume meter and update it.
|
|
|
|
|
hi,
It tell to create a pannel...
i need to use it in a form...
private SampleProvider
CreateInputStream(string
fileName)
Thanks & Regards,
HInshin
|
|
|
Coordinator
Dec 7, 2012 at 8:28 AM
|
the exact same code will work in a form.
|
|
|
|
|
Hi,
can you please tell me the sample code for that ... I tried a lot but I was not able to find that . please tell the solution.
Thanks & Regards,
Hinshin
|
|
|
|
|
Hi,
can you please tell me the sample code for that ... I tried a lot but I was not able to find that . please tell the solution.
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 9, 2012 at 7:03 AM
|
This is the important bit in the demo - we wrap our input stream in a MeteringSampleProvider, and subscribe to stream volume
var postVolumeMeter = new MeteringSampleProvider(waveChannel);
postVolumeMeter.StreamVolume += OnPostVolumeMeter;
Then in the event handler, set the value of your volume meter:
void OnPostVolumeMeter(object sender, StreamVolumeEventArgs e)
{
// we know it is stereo
volumeMeter1.Amplitude = e.MaxSampleValues[0];
volumeMeter2.Amplitude = e.MaxSampleValues[1];
}
|
|
|
|
|
Hi,
I was always getting null value for InputFileFormats and getting error like this...
Value cannot be null.Parameter name: source
[ImportMany(typeof(IInputFileFormatPlugin))]
public IEnumerable<IInputFileFormatPlugin> InputFileFormats { get; set; }
private IInputFileFormatPlugin GetPluginForFile(string fileName)
{
return (from f in this.InputFileFormats where fileName.EndsWith(f.Extension, StringComparison.OrdinalIgnoreCase) select f).FirstOrDefault();
}
I was using AudioFileReader...
is there any different using wavestream and AudioFileReader.
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 9, 2012 at 4:21 PM
|
just use AudioFileReader, that will make a SampleProvider from most playable types.
On 9 December 2012 15:59, hinshin <notifications@codeplex.com> wrote:
From: hinshin
Hi,
I was always getting null value for InputFileFormats and getting error like this...
Value cannot be null.Parameter name: source
[ImportMany(typeof(IInputFileFormatPlugin))]
public IEnumerable<IInputFileFormatPlugin> InputFileFormats { get; set; }
private IInputFileFormatPlugin GetPluginForFile(string fileName)
{
return (from f in this.InputFileFormats where fileName.EndsWith(f.Extension, StringComparison.OrdinalIgnoreCase) select f).FirstOrDefault();
}
I was using AudioFileReader...
is there any different using wavestream and AudioFileReader.
Thanks & Regards,
Hinshin
|
|
|
|
|
Hi,
I done every think like Audioplayback sample in NAudio..... But There is no cjhange in VOlume Meter...
my code are,
Play Button Click
private
void button2_Click(object
sender, EventArgs e)
if (player !=
null)
{
if (player.PlaybackState ==
PlaybackState.Paused)
}
else
{
player.DeviceNumber = 3;
reader =new
AudioFileReader(fileName);
player.Init(reader);
player.Play();
}
}
ISampleProvider sampleProvider =
null; try
{
sampleProvider = CreateInputStream(fileName);
}
catch(Exception createException)
{
MessageBox.Show(String.Format("{0}",
createException.Message), "Error Loading File");
return;
}
try
{
player.Init(new
SampleToWaveProvider(sampleProvider));
}
catch (Exception
initException)
{
MessageBox.Show(String.Format("{0}",
initException.Message), "Error Initializing Output");
return;
}
}
private ISampleProvider CreateInputStream(string
fileName)
if (plugin ==
null)
}
this.fileWaveStream = plugin.CreateWaveStream(fileName);
var waveChannel =
new
SampleChannel(this.fileWaveStream,
true);
this.setVolumeDelegate = (vol) => waveChannel.Volume = vol;
var postVolumeMeter =
new
MeteringSampleProvider(waveChannel);
postVolumeMeter.StreamVolume += OnPostVolumeMeter;
return postVolumeMeter;
}
void OnPostVolumeMeter(object
sender, StreamVolumeEventArgs e)
{
volumeMeter1.Amplitude = e.MaxSampleValues[0];
volumeMeter2.Amplitude = e.MaxSampleValues[1];
}
where I was doing wrong. please guide me to display volume meter.
Thanks & Regards,
Hinshin
{
throw
new
InvalidOperationException("Unsupported
file extension");
{
var plugin = GetPluginForFile(fileName);
player.Volume = (float)1.0;
|
|
|
Coordinator
Dec 10, 2012 at 8:21 AM
|
Are you hearing the audio? Also, try putting a breakpoint in OnPostVolumeMeter and seeing if it gets hit.
|
|
|
Dec 10, 2012 at 10:07 AM
Edited Dec 10, 2012 at 10:34 AM
|
hi,
yes i am hearing audio, it is not hitting OnPostVOlumeMeter event..
private IInputFileFormatPlugin GetPluginForFile(string fileName)
{
return (from f in this.InputFileFormats where fileName.EndsWith(f.Extension, StringComparison.OrdinalIgnoreCase) select f).FirstOrDefault();
}
It returns null value for me...
|
|
|
Coordinator
Dec 10, 2012 at 1:10 PM
|
don't use GetPluginForFile at all. Just make an AudioFileReader. That is all you need to do.
this.fileWaveStream = new AudioFileReader(fileName);
|
|
|
|
|
Hi,
My exact code is,
play button click
reader = new AudioFileReader(fileName);
player.Init(reader);
player.Play();
ISampleProvider sampleProvider = null;
sampleProvider = CreateInputStream(fileName);
return;
private ISampleProvider CreateInputStream(string fileName)
{
this.fileWaveStream = new AudioFileReader(fileName);
var waveChannel = new SampleChannel(this.fileWaveStream, true);
var postVolumeMeter = new MeteringSampleProvider(waveChannel);
postVolumeMeter.StreamVolume += OnPostVolumeMeter;
return postVolumeMeter;
}
void OnPostVolumeMeter(object sender, StreamVolumeEventArgs e)
{
volumeMeter1.Amplitude = e.MaxSampleValues[0];
volumeMeter2.Amplitude = e.MaxSampleValues[1];
}
But it was not hitting OnPostVolumeMeter event... Please correct my mistake...
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 10, 2012 at 2:16 PM
|
the thing you pass to Init must have the metering sample provider in the audio pipeline or it will have no effect. Try this:
reader = new AudioFileReader(fileName);
var postVolumeMeter = new MeteringSampleProvider(reader);
postVolumeMeter.StreamVolume += OnPostVolumeMeter;
player.Init(postVolumeMeter);
player.Play();
|
|
|
|
|
Hi,
I was getting error because of invalid parameter....
The best overloaded method match for 'NAudio.Wave.WaveOut.Init(NAudio.Wave.IWaveProvider)' has some invalid arguments
Argument '1': cannot convert from 'NAudio.Wave.SampleProviders.MeteringSampleProvider' to 'NAudio.Wave.IWaveProvider'
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 11, 2012 at 7:23 AM
|
ah yes, convert to IWaveProvider (I'm planning to make that step automatic for future NAudio versions). You've already got the code that does this elsewhere in your app:
player.Init(new
SampleToWaveProvider(postVolumeMeter));
|
|
|
|
|
hi,
Now it not playing and hitting OnPostVolumeMeter(object sender, StreamVolumeEventArgs e) event
Thanks & Regards,
Hinshin
|
|
|
|
|
Hi,
Thankyou for your response I got that (volume meter).
I was not able to play wave file which has 319 kbps of Bit Rate...
Thanks & Regards,
Hinshin
|
|
|
|
|
Hi,
I was not able to play wave file which has 319 kbps of Bit Rate...
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 12, 2012 at 6:28 AM
|
I'll need more information than that if you want help. What is the WaveFormat of the WAV file and what error message did you see?
Mark
|
|
|
|
|
hi,
I was playing wave file with ( Bit Rate: 319 kbps, Audio Sample Rate: 44 kHz) and I was getting the following error...
NoDriver calling acmFormatSuggest
Thanks & Regards,
Hinshin
|
|
|
Coordinator
Dec 12, 2012 at 8:15 PM
|
This means you have no ACM codec installed on your computer that can perform the requested conversion. You need to tell me what WaveFormat you are using (the most important thing is the Encoding).
For a detailed explanation, please read my article on CodeProject:
http://www.codeproject.com/Articles/501521/How-to-convert-between-most-audio-formats-in-NET
Mark
|
|