This project has moved. For the latest updates, please go here.

ActiveStream.Position Returns 0

Jun 7, 2011 at 12:12 PM

Hi,

Great work!!! Thanks for posting this wonderful application.

I was trying to convert the code to play the WAV files in the Sample_NAudio application. And i am able to load the WAV Stream and play the files. But ActiveStream.Position property is always returning 0 and it doesn't accept any values as well. I modified the input stream as shownbelow to allow WAV file stream.

  inputStream = new WaveChannel32(new WaveFileReader(path));

Any idea why this is? 

Please guide what I am missing here?

Best Regards

Vince


Coordinator
Jun 7, 2011 at 6:57 PM

Vince,

Give this a try:

ActiveStream = new WaveFileReader(path);
if (ActiveStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm && ActiveStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
{
    ActiveStream = WaveFormatConversionStream.CreatePcmStream(ActiveStream);
    ActiveStream = new BlockAlignReductionStream(ActiveStream);
}

It seems to work for me. Also, make sure you do the same thing for the WaveForm Generation worker method if you're using the sample application. Let me know if you're still running into trouble.

Jun 8, 2011 at 3:09 PM
Edited Jun 9, 2011 at 3:14 PM

Hi Jacob,

Thanks for getting back to me.

I am using the Sample_NAudio applictation. In that, i have added the following piece of code 

                    if (Path.GetExtension(path) == ".mp3")
                    {
                        ActiveStream = new Mp3FileReader(path);
                    }
                    elseif (Path.GetExtension(path) == ".wav")
                    {
                        ActiveStream = new WaveFileReader(path);
                        if (ActiveStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm && ActiveStream.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
                        {
                            ActiveStream = WaveFormatConversionStream.CreatePcmStream(ActiveStream);
                            ActiveStream = new BlockAlignReductionStream(ActiveStream);
                        }

                    }

                    inputStream = new WaveChannel32(ActiveStream);

in functions OpenFile() and waveformGenerateWorker_DoWork. I am able to play the file and also that plots the Graph and timeline. But the ChannelPosition value is never updated in the positionTimer_Tick as the ActiveStream.Postion value is always 0. But when i click the CurrentPostion indicator in timeLine control, that value is read into the ActiveStream.Position value.  Is this because the audio is played from ActiveStream? The inputStream.Position is giving updated values.

Hence the ChannelPosition indicator is not moving or doesn't play where i keep the indicator.

I use the same music with mp3 and wav versions for testing the comparison. The mp3 version has BlockAlign = 4 while that is 2 for wav. MP3 is 2 channel while that is 1 for wav. is this some thing related ?

Please advice how can i get this moving?

Best Regards

Vince


Jun 10, 2011 at 11:50 AM

Thanks Jacob.. It worked.

Best Regards

Vineesh