This project has moved and is read-only. For the latest updates, please go here.

How to stop current playback and play another

May 7, 2013 at 11:12 AM
I'm doing some QA tools for audio and it happended, that i started to use NAudio. So far, so nice, but i've one issue.

I'm displaying list of files in DataGridView with button for each of them to play it out. Button handler looks like this (right now, it's about to change i hope).
private void showFilesGrid_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if( showFilesGrid.Columns[e.ColumnIndex].Name == "fileAction")
            {
                string fullFileName = showFilesGrid.Rows[e.RowIndex].Cells["fullPathDataGridView"].Value.ToString();
                WaveStream outputStream = new WaveFileReader(fullFileName);
                WaveChannel32 volumeStream = new WaveChannel32(outputStream);
                WaveOutEvent player = new WaveOutEvent();
                player.Init(volumeStream);
                player.Play();

            }
        } 
What i need is to somehow stop playback of current file when user chooses to play another one. I'm pretty novice in c#, visual studio and this stuff, but good kick should help me to solve this problem :)
May 7, 2013 at 5:21 PM
keep hold of your reference to WaveOutEvent as a member of your class, so you can stop it. It is usually best to then Dispose it, and create another one for playback.