audio5js
audio5js copied to clipboard
Uncaught (in promise) DOMException: play() failed because ...
Following up on #88 , how to catch this error?
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD
this.play() returns undefined whether it works or not. Setting throw_errors = true doesn't seem to make a difference. Wrapping it with try { this.play() } catch(err) { } does not catch an error. Using this.on('error', function...., this); doesn't receive the event. I thought of testing this.playing but it (correctly) says the audio5js instance is not playing immediately after calling this.play()
Google documentation says to check the return value of audio.play() for a promise object, and attach a callback to that promise object, but I don't know how to dig a promise return value out of audio5js.play()
To be clear: I don't expect audio5js.play() to start working as before, but I would like to be able to detect its failure so I can notify other components or notify the end-user.
Not sure exactly what you're expecting here - If the problem is due to user not interacting with the DOM, then the solution is to trigger play on DOM interaction
How do I write code that detects audio5js.play() did not succeed, so the code can respond (ie. asking the user to click on a 'start' button, halting animation that is supposed to synch up with the audio, etc.).
I'm not looking for a workaround for the Google Chrome scenario -- that was already answerd in #88 whilch I cited so you'd know I already read it.
but for what use-case? is this on a mobile or a desktop browser?
Either. I call a method on this object -- how does the program sense if it succeeded or failed?
Usually it would be a return value, or catching an exception in a try { } catch { } block, or I'd use a callback hooked into an error event, but as I already said above these don't work. Is there something else I should be doing to sense if the method call succeeded?
@mozai what exactly is the source of the issue here? Are you experiencing problems on mobile browsers or desktop?
I'm having the same issue on Android Chrome. I fixed the error in desktop by provided some initial interaction between the user and the application.
My use case is a monitoring application and requires to set off an audio as an alarm. is there any way an event (not user input) can trigger audio.play() for android chrome?
No - As far as I know, on mobile browsers you need a user interaction event to trigger play()
I have this error when a user manually reloads a page with audio on it. The audio object is created with new Audio(), and was previously successfully playing, but after the user reloads it, while the object exists, it fails to play and I get this error in the console, but there's no way to tell that it hasn't played, in order to catch the error and attempt some recovery....it just breaks. This is on desktop with chrome devtools open and mobile emulation enabled.
@davidmaxwaterman I'm no longer actively maintaining this repo. My suggestion is to move away from it to native HTML5 audio which is widely supported by all major browsers
I should have been clear, but I am using the native html5 audio class. I came to this issue by searching for the error message, which seems to come from the underlying platform.
OK. Thanks for clarifying that