When HTML5 audio finishes playing, the .ended event doesn't fire if the web app is running in the background or if the screen is off.
Here's a simple page that demonstrates the problem: http://bitshuvafiles01.com/iOSAudioBugRepro/audioError.html
Steps to reproduce:
1. Create web page with a single <audio> element.
3. Add an .ended event handler to the audio element. In the .ended event handler, set audio.src = "song2.mp3", and .play().
4. While song1.mp3 is playing, turn off the phone screen.
5. Wait for the audio to finish. When it finishes, audio will stop; song2.mp3 will never.
Expected results: The audio.ended event fires and the next song starts playing.
Actual results: The audio.ended event never fires because the screen is off or because Safari is in the background; JS execution is suspended.
Additional info: While suspending JS execution is wise for battery life reasons, it harms the user experience when listening to audio on the web. Either don't suspend JS execution for tabs playing audio, or at least fire the .ended event so we can play the next song.
The web proces, normally suspended when in the background, is kept alive while playing audio (and for a few other reasons). The 'ended' event is fired asynchronously, so while the event is scheduled immediately when playback finishes, the task is suspended before the next runloop so the event doesn't fire until the process resumes.
We should probably postpone suspension for a few cycles when playback stops to give scripts an opportunity to restart playback.
>> "We should probably postpone suspension for a few cycles when playback stops to give scripts an opportunity to restart playback."
Ah, that would wonderful and would fix the problem perfectly.
Hi any idea when this could be committed and it starts to hit upstream?
(In reply to craigwharding from comment #4)
> Hi any idea when this could be committed and it starts to hit upstream?
There's nothing to be committed because there's no patch yet.
(This is an open source project)
This morning I received more reports of this same bug from my users on iOS. Any chance we get this fixed in 2018?
Confirmed still an issue.
*** Bug 204080 has been marked as a duplicate of this bug. ***
Created attachment 383493 [details]
Comment on attachment 383493 [details]
View in context: https://bugs.webkit.org/attachment.cgi?id=383493&action=review
r=me once the bots are happy
> +RUN(internals.setMediaElementRestrictions(audio, "RequireUserGestureForAudioRateChange"))
Oops, look like you need to regenerate this file.
> + run('audio.load()');
> + testExpected('internals.bestMediaElementForShowingPlaybackControlsManager("NowPlaying")', audio);
It would be better to test for NowPlaying status after a delay, e.g. after an 'emptied' event.
Created attachment 383656 [details]
Patch for landing
Comment on attachment 383656 [details]
Patch for landing
Clearing flags on attachment: 383656
Committed r252692: <https://trac.webkit.org/changeset/252692>
All reviewed patches have been landed. Closing bug.