Replaced custom hack for preloading audios and fixed #299.#471
Replaced custom hack for preloading audios and fixed #299.#471MarkusBordihn wants to merge 3 commits into
Conversation
For preloading audio files the attribute "preload=auto" should be used. See: https://developer.mozilla.org/de/docs/Web/HTML/Element/audio
| if (ext && audioTest.canPlayType('audio/' + ext[1])) { | ||
| // Found an audio format we can play. | ||
| sound = new window['Audio'](filename); | ||
| sound.setAttribute('preload', 'auto'); |
There was a problem hiding this comment.
Does this work on iOS?
There was a problem hiding this comment.
The preload attribute is an official attribute, so it will not break anything.
See https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload
The former solution has not really worked on iOS:
// iOS can only process one sound at a time. Trying to load more than one
// corrupts the earlier ones. Just load one and leave the others uncached.
...
According MDN in most cases the mobile browsers will load the Metadata but not buffer the audio to 100%, which is by design and expected.
That's also the reason why the former solution not really worked on iOS.
There was a problem hiding this comment.
This change breaks iOS. The existing solution will ensure that the click sound plays, something we want to preserve. I've tried several variations of this PR on iOS but have not yet been able to come up with something that plays any sound.
There was a problem hiding this comment.
Out of curiosity, why you are not using the "required" method (Web Audio API) from Apple to load the sound files on iOS to make sure that they are working as expected ?
See:
- https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
- https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html#//apple_ref/doc/uid/TP40009523-CH6-SW1
The current solution is "unsupported" for desktop browsers and will throw the given error message.
I'm not a friend of browser specific solutions, but in this case it seems there is no other way.
|
I will close this PR for now. Let me know if there is any interest for this solution in the future. |
For preloading audio files the attribute "preload=auto" should be used.
See: https://developer.mozilla.org/en/docs/Web/HTML/Element/audio
Regenerated all files to include the changes.
Unit tests and workspace tests looks fine without any error in the console.