I’m trying to use html5 audio with Dart and Chrome, and I’m going the easy way of using AudioElement as much as possible. I want to be able to pause sound and resume it later. I have:
startSound() {
audioElement.src = "foo";
audioElement.load();
audioElement.play();
}
pause() {
this.time = audioElement.currentTime;
audioElement.pause();
}
unpause() {
audioElement.currentTime = this.time;
audioElement.play();
}
These are hooked up to event handlers, so when someone clicks the ‘pause’ button, playback stops. When they hit the ‘resume’ button, though, playback resumes for only about half a second before stopping again.
How do I get audio to resume properly?
There appears to be a timing issue in Chrome. You need to tell Chrome to play, then pause again, then play again, with a short delay between each.
A working version of the
unpausemethod is: