WASM: Fix issues with play, pause, and browser autoplay blocking#774
WASM: Fix issues with play, pause, and browser autoplay blocking#774DouglasDwyer wants to merge 4 commits intoRustAudio:masterfrom
play, pause, and browser autoplay blocking#774Conversation
|
Thanks for your PR! I think the
Can you explain why you prefer the new behaviour? |
|
@est31 sure! Let me emphasize here that this new behavior should be non-breaking: it is a strict superset of the old behavior, and thus backwards compatible. |
|
@DouglasDwyer my question was more why you think it's a good idea, not why it's allowed for us to do it. I agree that we are allowed to do it, but I want to hear arguments why the new behaviour is better than the old one. Why is it bad if it hangs? What does hanging mean? can you still interact? Why is it better that it is muted but plays in the background? |
|
Okay. My argument above was meant to state that I think it's a good idea because it gives users an additional option: they can have the audio not hang if that's what they want. Surely having that option is better than not having it? Anyway, let me try and answer your questions.
The audio stream is not started, and no audio frames are consumed from the output callback. The application otherwise functions normally.
There's no way to detect the hanging behavior from Rust; currently, the Further, having the stream hang could lead to audio buffer overruns. If audio frames are being streamed into the application, but the output callback is never invoked, then these frames could accumulate and cause an out-of-memory issue.
Because as an end user, I expect that a successful call to |
|
As a user, I'd rather (web) applications whose audio I can't hear not be spending potentially large amounts of CPU time rendering said inaudible audio. |
|
@Ralith, an alternative solution that I think would be acceptable would be for |
|
I think this PR is extremely valuable for the users of @Ralith mentioned issues with unused cpu usage while the audio is muted. I'd like to add that (from what I can) tell it would only be rendering silent audio in the second or two between the user opening the tab and clicking on the page. |
|
+1 for this PR getting merged. it should help me get multi-threaded audio loading working on the web |
|
+1 too as I was struggling with the same problems in WASM world. |
|
Currently bevy +1 |
|
i just got this issue as well. i require +atomics for something else, but right now it's crashing on both chrome and firefox |
|
Maintainers - please let me know if there is anything more that I can do to push this PR forward! |
|
i can confirm this PR solved it |
|
I'm still not really happy about the hang removal changes. But outside of that, I think the general idea of the PR looks good. I need to give it a closer look though. |
|
Maintainers (@est31?) can we find a way to get this merged? |
|
Any updates on this PR? |
|
Given #837 I'm closing this, but open for any of the non controversial changes to be submitted in a PR. Thanks. |
This PR improves the behavior of audio streams on WASM in the following ways:
playmultiple times on aStreamonly callsresumeon the underlyingAudioContexta single time, and only spawns background audio callbacks once. Previously, callingplayfrom Rust multiple times in succession would spawn multiple closure instances and lead to stuttering audio.AudioContextto remain in theSuspendedstate. This is problematic forcpal's WASM backend, because from the Rust side there is no way to determine whether audio playback has begun. This PR causes theStreamto read and discard audio frames while the context is blocked, so it's as if the audio stream is always playing (but muted until the user interacts) onceplayis called. Previously, the audio would simply hang if the user had not yet interacted with the page.cpalwith the+atomicstarget feature enabled. This is accomplished by adding a secondary Javascript-side array into which frames are copied before they are played, since you cannot send frames to Javascript from aSharedArrayBufferdirectly.I'm happy to make any improvements necessary to get this PR merged! I would like to see all of these behaviors available in
cpal, because they are the best fit for my use case.