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

Using WaveOutEvent to playback in a cycle

Jun 1, 2012 at 2:27 PM

When using WaveOutEvent to endlessly playback audio between a start and end marker only works reliably if waveStream.CurrentTime is re-winded to start marker when it reaches the end marker.

Stopping playback on reaching the end marker, re-winding waveStream.CurrentTime and then issuing Play is not robust. Sometimes issuing Play no audio is played even though the PlaybackState is 'Playing'.

Normal play-out (without the use of start and end marker) is also problematic. On reaching the end of playback the stop event is fired which is used to rewind the wavestream to 0. On issuing the next Play (manually clicking on a button) no audio is played even though the PlaybackState is 'Playing'. After another pause/play cycle play-out is working again.

In your demo program no rewinding takes place as issuing a play freshly creates a new waveout which would neatly mask this issue.

Any ideas?

Jun 2, 2012 at 6:20 PM

I also experience the problem with the next Play command resulting in PlaybackState == Playing but the audio file is not actually playing.  I am using an event timer to track the progress of the audio file.  If CurrentTime.Ticks is not incrementing, try again.  This happens occasionally and stops my player.  For now I just issue a command to try the track again.

                if (_ticks == AudioRoutines.FileWaveStream.CurrentTime.Ticks && AudioRoutines.Waveplayer.PlaybackState==PlaybackState.Playing)
                {
                    if (_ticks == AudioRoutines.FileWaveStream.TotalTime.Ticks) return;
                    PlayOrderListIndex = PlayOrderListIndex - 1;
                    if (PlayOrderListIndex < 0) PlayOrderListIndex = 0;
                    TrackTimer.Stop();
                    PlayNexttrack();
                    return;
                }
                _ticks = AudioRoutines.FileWaveStream.CurrentTime.Ticks;

Jun 4, 2012 at 12:55 AM

Modifying WaveOutEvent.Play() as follows resolved this issue (for me):

        public void Play()       

{           

if (playbackState == PlaybackState.Stopped)           

{               

playbackState = PlaybackState.Playing;

ThreadPool.QueueUserWorkItem((state) => PlaybackThread(), null);

                callbackEvent.Set(); // kicking the thread here can only be good            <=========Line Added========

}

else if (playbackState == PlaybackState.Paused)

{

                Resume();

                callbackEvent.Set(); // give the thread a kick

}

        }

 

So Mark if you agree make it part of the official code.

Coordinator
Jun 11, 2012 at 10:28 AM

thanks for this suggestion. I'll try to get something like this incorporated in for a future version. Probably WaveInEvent would need a similar fix