Kangjun Heo
Kangjun Heo

Reputation: 1081

Program halts when NAudio WaveOut.init();

I'm making my own musicplayer with NAudio Library, and configuring playlist function.

Everything is OK, but I got a little problem to complete it.

When playback is completed, call playback function to play next music, and program halt.

I set breakpoint and execute line by line, and I found which line makes the program halt.

AudioFileReader _audioFileReader;
IWavePlayer _waveOutDevice = new WaveOut();
(...)
private void PlaybackStopped(object sender, EventArgs e)
{
    if (_manual_stop == false)
    {
        if (nowIndex + 1 == listMusic.Items.Count)
        {
            btnPlayCtrl.Text = "▶";
            return;
        }
        else
        {
            nowIndex++;
            playMusic();
        }
    }
    else
    {
        btnPlayCtrl.Text = "▶";
        return;
    }

}

private void playMusic()
{
    if (_paused == true)
    {
        _waveOutDevice.Play();
        _paused = false;
        return;
    }

    stopMusic();

    _audioFileReader = new AudioFileReader(listMusic.Items[nowIndex].Text);
    _waveOutDevice.Init(new WaveChannel32(_audioFileReader)); //It makes program halt

    getProperties(listMusic.Items[nowIndex].Text);
    _waveOutDevice.Play();

    _manual_stop = false;
}

I used 1.7.3.0 version of NAudio and tried to replace another copy of DLL, but it doesn't work.

Upvotes: 0

Views: 687

Answers (1)

Mark Heath
Mark Heath

Reputation: 49492

You should only call Init once on an output device. Try closing the existing WaveOut device and creating a new one to play the next file.

Upvotes: 2

Related Questions