What I’m trying to do:
Play a sound (like a chime notification) called via python function, it works on desktop but not on mobile (throws error).
What I’ve tried and what’s not working:
I have my audio in native libraries, and it’s called via call_js in the python functions and works great on the computer.
On the iPhone and iPad however, it doesn’t work. It throws an unhandled runtime error.
When debugging Chrome on iOS, it will show this error:
NotAllowedError: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
I’ve tried getting around it by having a button clicked to play the sound first, then change source, etc. but for the life of me I can’t figure it out. Even the html button with a direct onclick sound source won’t play and will throw an error.
Does anyone know how to get around this? Again, it works fine on desktop but mobile is throwing errors.
This is my Native Lib Code Sample:
<script>
successSound = new Audio("_/theme/success.wav");
failureSound = new Audio("_/theme/failure.wav");
doneSound = new Audio("_/theme/done.wav");
function success(){
successSound.currentTime = 0;
failureSound.currentTime = 0;
doneSound.currentTime = 0;
successSound.play();
};
function failure(){
successSound.currentTime = 0;
failureSound.currentTime = 0;
doneSound.currentTime = 0;
failureSound.play();
};
function done(){
successSound.currentTime = 0;
failureSound.currentTime = 0;
doneSound.currentTime = 0;
doneSound.play();
};
</script>