-
pausing a ByteArray sound
hi,
I'm playing and stopping bytes, which goes well, but when I try to pause the audio, and then resume, it skips about a second. probably someting with chunks of bytes, but I wonder how to pause and resume more precisely. This code causes the skipping:
Actionscript Code:
private function startPlaying( bytes: ByteArray ):void { _soundClip = bytes; _soundClip.position = 0; _sound = new Sound(); _sound.addEventListener( SampleDataEvent.SAMPLE_DATA, sampleDataHandler, false, 0, true ); _channel = _sound.play(); _channel.addEventListener( Event.SOUND_COMPLETE, soundCompleteHandler, false, 0, true ); } public function stopPlaying( ):void { if( _channel ) _channel.stop(); } public function pausePlaying():void { _pausedPosition = _channel.position; _channel.stop(); } public function resumePlaying():void { _channel = _sound.play( pausedPosition ); } private function sampleDataHandler( e: SampleDataEvent ):void { if( !_soundClip.bytesAvailable > 0 ) return; for( var i: int = 0; i < 8192; i++ ) { var sample: Number = 0; if( _soundClip.bytesAvailable > 0 ) sample = _soundClip.readFloat(); e.data.writeFloat(sample); e.data.writeFloat(sample); } }
thanks in advance,
Jerryjj.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|