tags:

views:

43

answers:

1

I tried to use this:

private void CreateDevice()
{
    _playbackDevice = new WaveOut();
    _playbackDevice.PlaybackStopped += PlaybackDevicePlaybackStopped;
}

void PlaybackDevicePlaybackStopped(object sender, EventArgs e)
{
    if (OnPlaybackStopped != null)
    {
        OnPlaybackStopped(this, e);
    }
}

But it never invoked.

Then I tried to use the PlaybackState by polling the property with a timer:

public PlaybackState PlaybackState
{
    get
    {
        if (_playbackDevice == null)
            return default(PlaybackState);

        return _playbackDevice.PlaybackState;
    }
}

But when the song ends it does not change to "stopped". But when I call manually Stop it changes correctly.

Can someone help me?

There seems to be a bug ... http://naudio.codeplex.com/WorkItem/View.aspx?WorkItemId=10726

A: 

Because NAudio is designed to allow you to do more complicated things than simply playing one file, it will not necessarily stop at the end of a file. What determines whether WaveOut will stop is whether we stop feeding it data or not. Some WaveStreams in NAudio do stop providing data when they have reached the end of a file, but other WaveStreams will happily return buffers full of zeroes from their Read method as many times as they are called. So auto-stopping depends a lot on the graph of WaveStreams you have constructed.

Because of this you may need to determine when to stop by when you have finished reading the contents of the file to be played. I realise this is not an ideal situation, and I am still trying to come up with a design that works well both for those who just want to play a single file, and for those who are doing something a bit more involved.

Mark Heath