Pergunta

It sounds like a simple question, but I cant figure it out.

I am playing a wav file using Naudio (I am initiating the WaveOut object with the path of the file).

The Pause and Play works fine

The problem - when I try to stop (pause and return to the begining of the file) - it just pauses the file (like Pause).

Here is my code:

public class FilePlayer
{


    private WaveFileReader waveFileReader;
    protected static WaveFormat _waveFormat = new WaveFormat(8000, 16, 1);
    protected IWavePlayer _waveout = new WaveOut(WaveCallbackInfo.FunctionCallback());


    public FilePlayer(string path)
    {
        try
        {
            waveFileReader = new WaveFileReader(path);
            _waveout.Init(waveFileReader);
        }
        catch (Exception)
        {

        }
    }



    public void PlayCall()
    {
        try
        {
            _waveout.Play();
        }
        catch
        { }
    }


    public void PauseCall()
    {
        _waveout.Pause();
    }


    public void StopCall()
    {
        _waveout.Stop();
    }

}

Any help? thnaks!

Foi útil?

Solução

Stop is not supposed to go back to the beginning of the file. It just stops the audio device from playing. Handle the PlaybackStopped event and set the Position of your audio file to 0 if that is what you require.

Also, I recommend against using Function callbacks. Use WaveOutEvent instead if you are not running inside a GUI application.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top