Closed fnoks closed 10 months ago
@otacke : Thanks.
@otacke The HTMLAudioElement has a preload
property which defaults to auto
. This means sounds are preloaded by default before they are played.
You can test this by looking in your browser dev tools network tab. Sounds are loaded as soon as you set the src
attribute on the audio object. You have to manually change preload
to none
for the sounds to be loaded when you play them.
https://developer.mozilla.org/en-US/docs/Web/Media/Audio_and_video_delivery/Cross-browser_audio_basics
In some browsers preload
defaults to metadata
instead so I've updated the code to make sure preload is set to auto.
For our specific case, the 2 sounds that h5p-single-choice-set uses are below 45 kB in size each so preloading them, even on a mobile network, should not be a problem.
@devland Welcome to the world of Apple who often just "think differently". iOS ignores the 'preload' attribute as I tried to point out. See "Note: This value is often ignored on mobile platforms." in the document that you linked to and https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html in particular. Cite: "Safari on iOS never preloads." That's why you will have a noticable delay on iOS (real devices, not neccessarily Browserstack). If that delay doesn't bother you, that's fine with me, but I wanted to point out that you will get one on iOS.
@otacke I've updated the player.src
so that it uses a dynamically generated binary url object via URL.createObjectURL
based on a fetch
response blob.
This should bypass the need of relying on the preload attribute.
@devland As I said: I just wanted to point out that iOS needs some extra treatment and usually one uses the WebAudio API - I don't need to consent or be informed ;-) @fnoks Can't access JI-3994, so I cannot hint there that this should be tested on a real iOS phone (with a cellular network connection).
@fnoks Have you tested this on iOS in a real world setting over a cellular network? Playing audio can be delayed, because using the regular
Audio
iOS doesn't preload audio content in order to save bandwidth. At least that was a problem we faced around 1 year ago. WebAudio API was the way to go, and that's what SoundJS is using if I recall correctly.