naudio - C# Audio File is played in a loop although it is stopped -
i have older implementation using naudio 1.6 play ring tone signalling incoming call in application. user acceptes call, stop playback.
basically follwing done:
1. event call must signalled, timer started
2. inside timer play()
on player
3. when timer starts again, check performed if file played checking currenttime
property against totaltime
propery of wavestream
4. when user accepts call, stop()
called on player , stop timer
the point is, run in cases playback still repeated although timer stopped , stop() called on player.
in following link read classes bufferedwaveprovider
, wavechannel32
used in code padding buffer zero.
http://mark-dot-net.blogspot.com/2011/05/naudio-and-playbackstopped-problem.html
is possible non-stopping playback due usage of classes bufferedwaveprovider
, wavechannel32
?
in naudio 1.7 audiofilereader
class there. class padding zeros? did not find property padwithzeroes
in class. make use audiofilereader
in case of looped playback?
below code of current implementation of timerelapsed
void timerelapsed(object sender, elapsedeventargs e) { try { wavestream stream = _audiostream wavestream; if (stream != null && stream.currenttime >= stream.totaltime ) { startplayback(); } } catch (exception ex) { //do actions here } }
the following code creates input stream:
private wavestream createwavinputstream(string path) { wavestream readerstream = new wavefilereader(path); if (readerstream.waveformat.encoding != waveformatencoding.pcm) { readerstream = waveformatconversionstream.createpcmstream(readerstream); readerstream = new blockalignreductionstream(readerstream); } if (readerstream.waveformat.bitspersample != 16) { var format = new waveformat(readerstream.waveformat.samplerate, 16, readerstream.waveformat.channels); readerstream = new waveformatconversionstream(format, readerstream); } wavechannel32 inputstream = new wavechannel32(readerstream); return inputstream; }
Comments
Post a Comment