So I have an audio element in my HTML:
<audio id="success-sound" class="hidden">
<source src="sound/success.mp3" type="audio/mpeg">
</audio>
The sound is played on click / touch event. It works fine in Safari on my Mac, the music plays. I am creating an iOS app though with a web view where I ember my HTML5 app. When I try the app in iPad 6.1 simulator and debug the console, I can see this error:
INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.
This is the line that's failing:
var successSound = document.getElementById("success-sound");
successSound.currentTime = 0;
successSound.play();
Any ideas?
Btw, I have another audio element with a soundtrack which works:
function startSoundtrack() {
soundtrack.play();
soundtrack.addEventListener('ended', function () {
var audio = this;
setTimeout(function () {
audio.currentTime = 0;
audio.play();
}, 5000);
}, false);
}