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

Where to discuss NAudio 1.7-alpha

May 19, 2013 at 8:52 PM
Where is an appropriate place to discuss NAudio 1.7-aplha builds?

I am very interested in using MediaFoundationReader. I have used it to some success, but I cannot detect stream end in order to play another file. The stream just repeats forever.

Snippet:
// fileWaveStream is of type WaveStream
FileWaveStream = new MediaFoundationReader(fileNameToPlay,
                     new MediaFoundationReader.MediaFoundationReaderSettings
                        {
                            RepositionInRead = true,
                            RequestFloatOutput = false,
                            SingleReaderObject = false
                        });
// Waveplayer is of type IWavePlayer
 wavePlayer.Init(FileWaveStream);
 wavePlayer.Play();
Coordinator
May 20, 2013 at 8:34 AM
That's very strange and unexpected. What sort of a file are you playing?
When you say "repeats" forever, do you mean it goes back to the start again? Or does it play silence?
May 20, 2013 at 9:10 PM
The file format I am using is either mp3 for flac. I installed the mfFlac codec to support flac in media foundation. http://sourceforge.net/projects/mfflac/

Interestingly enough in further testing the Waveplayer.PlaybackState never sets to PlaybackState.Stopped. So it gets to the end of the stream and just stops. The reason for the repeat was code I have to detect a threading problem ( https://naudio.codeplex.com/discussions/357995 ) where waveplayer would start to play a track and just stop. I have updated the code to also check if we are at the end of the stream and fire off the next track. While this works it doesnt seem ideal.

Any ideas on why wavePlayer isnt changing to PlaybackState.Stopped state at the end of the stream?
Coordinator
May 21, 2013 at 2:37 PM
What IWavePlayer implementation are you using?
The idea is that FileWaveStream's Read method should return 0 when it reaches the end. Then the wavePlayer knows that it can stop playing. So you could start by writing a simple test that keeps calling Read on your FileWaveStream (e.g. into a buffer of 1024) and ensure that it eventually returns 0.
Aug 31, 2013 at 8:08 PM
Sorry for very long delay in response. I had to work on another project. It turns out I was not hooking the stop event. I am now using Waveplayer.PlaybackStopped += WaveplayerPlaybackStopped; and it works as expected.