maxl0rd / standingwave3

Flash ActionScript3 dynamic audio library
http://www.noteflight.com
160 stars 25 forks source link

Bugfix for AudioPlayer stop()/play() bug #28

Closed georgiee closed 11 years ago

georgiee commented 11 years ago

This fixes an annoying bug in AudioPlayer. If you start and start the sample source over and over again you will notice that the sound plays in multiple speed dependent on how often you started the same source again.

I found that "handleSampleData" is called once after the stop method was called. My first workaround was a cool down phase for the audio player instance of some milliseconds because I expected a somewhat complex reason hidden in the underlying alchemy byte array access code. And yeah, that helped for the moment.

Some days later I looked at the code again and found the real cause. So simple. An orphaned event listener. Look at the pull request for the exact position of the fix. Simply remove the handler from the sound object when erasing the _sound object. In general this also prevents memory leaking.

if(_sound){
  _sound.removeEventListener(SampleDataEvent.SAMPLE_DATA, handleSampleData);
}
_sound = null;
Nathan-Smith commented 11 years ago

:+1:

maxl0rd commented 11 years ago

Hi georgiee

Thanks for the pull request. I have merged it in.

A previous FP (10.1?) would freak out if you yanked the sample handler. I think that this is why the code was that way. This issue is probably fixed now. In any case, our policy was to never reuse an AudioPlayer object, so this bug did not come up for us.