Bug 238113

Summary: Audio element playback ends early when src is a blob URL
Product: WebKit Reporter: Peter Fernandes <supersonicandtails>
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Major CC: cdumez, jer.noble, pete.jungwirth, supersonicandtails, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: iPhone / iPad   
OS: iOS 15   
Attachments:
Description Flags
Network tab while blob is playing none

Description Peter Fernandes 2022-03-19 11:23:17 PDT
When playing audio via an HTMLAudioElement instance and the src is a Blob URL, playback halts before the end of the track and the "ended" event is never fired on the audio element.

Steps to Reproduce:

Please see the jsfiddle link for a demo: https://jsfiddle.net/1yv7b82n/5/

1. Fetch an mp3 or other audio file and read the response body as a Blob
2. Get an object URL from the blob then set that URL as the src of an audio element
3. Call play() on the audio element

Expected:
The audio plays all the way through, and the onended event is fired after playback completes.

Actual:
Playback never completes and onended is never fired. In the example provided in the jsfiddle above, I observed playback ceasing several seconds before the actual end of the audio. I also notice my phone heating up after audio ends so maybe there is runaway CPU/memory usage somewhere.


Build Date & Hardware:

Safari on iOS 15.4 stable. Does not occur on Safari 15.4 (17613.1.17.1.6) on MacOS.
Comment 1 Radar WebKit Bug Importer 2022-03-21 22:23:56 PDT
<rdar://problem/90614038>
Comment 2 Pete Jungwirth 2022-03-23 22:28:22 PDT
Created attachment 455608 [details]
Network tab while blob is playing

This shows the packets on the Safari network tab with a smaller mp3 than the one submitted in the fiddle with the original bug - the last chunk repeats endlessly.
Comment 3 Pete Jungwirth 2022-03-23 22:32:57 PDT
To clarify the attachment - this bug happens any time a Blob exceeds 65536 bytes. Examining the network tab while the file is playing, it looks like the last chunk in the file never causes the ended event to fire, and it fetches endlessly with 206 returns. If you take the fiddle that was provided in the original post and use a smaller mp3, it's easier to see.
Comment 4 Jer Noble 2022-03-24 10:21:23 PDT
Thanks for this report. From the attachment, this looks like a dup of bug# 238170, recently fixed. Please CC yourself to that bug to follow along.

*** This bug has been marked as a duplicate of bug 238170 ***