-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "interrupted" state in AudioContext #2392
Comments
See also the followup comments: Summary: General agreement that we need this, but there are quite a few questions on what the state transitions are and what causes the transitions. These need to be finalized before we can update the spec. |
That's correct.
Please keep in mind that it's actually the user that's responsible for the interruption. The user has received a phone call and the user is talking on the phone. The user has switched to another app and the user is using the audio hardware there. The user is recording a video and saving it to the user's photo library. So to put it another way, the page must wait until the user allows the page to resume audio, mediated by the User Agent.
Yes, and this would cause the state to move to
I'd hate to freely expose to every web page the current state of whether the user is on the phone or not, so I'd argue to only move to the "interrupted" state from "running". |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
You seem to be suggesting that sites which care could implement some kind of "mute" behavior themselves. That's not the intent of this API; it's not the expectation that the User Agent will indicate to the page that the user is doing something else and the page should kindly mute itself. Rather, this is telling the page that audio playback will not continue, and it can take some action in response, like pausing the game being played, suspending an animation, etc.
On the platforms I am personally familiar with, this will not succeed. That new context will also enter the "interrupted" state, as that second context cannot get access to the audio hardware. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Teleconf: set priority to 2 for now. |
Virtual F2F 2021: We agree that having an "interrupted" state makes sense. However, we need more details on exactly how this is intended to work to be able to specify this properply. Christoph Guttandin mentioned that Safari sets the interrupted state if an audiocontext is silent and you switch tabs. When you switch back, it resumes. But if the context is playing, this doesn't happen. This all needs to be clarified. |
2023 TPAC Audio WG Discussion: |
I build a very simple demo which plays a sine wave and logs the https://stackblitz.com/edit/js-3w4eqh As far as I can tell the audio stops in any case on iOS 16.6 when the screen gets switched off. The However there are subtle differences. When the @jyavenard Is that expected or should I file a bug for that? |
It sounds like https://bugs.webkit.org/show_bug.cgi?id=261554 and yes, there’s an issue as the behaviour isn’t consistent between macOS and iOS. But only playback state will allow audio to be played while the page is suspended. Similar to how an audio/video element work |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hello! I have written an explainer to make progress on the |
Re-opening this issue.
suspend()
andresume()
are indeed important parts of this proposal, but the"interrupted"
state is important as well. During a phone call, (or other period of exclusive use of the audio hardware) requests toresume()
the AudioContext will always fail. An"interrupted"
state signals to the web page that, as opposed to merely"suspended"
, all requests toresume()
will reject.Additionally,
"interrupted"
is a state provided by the UA, rather than script running in the page. A UA could move the state from"running"
to"interrupted"
to"running"
again (if the interruption allows normal audio playback to resume afterwards), or from"running"
to"interrupted"
to"suspended"
(if audio playback is not allowed to resume automatically). In the first case, the page is free to react to the"interrupted"
state by pausing (e.g.) the video game, and un-pause when the state moves to"running"
after the interruption ends. In the second case, when the state moves to"suspended"
, the page can provide UI to restart playback (and the game) after the interruption. In either case, the page can choose to continue silently during the interruption."closed"
is not a substitute here, as there is no mechanism for moving from"closed"
to"running"
."suspended"
is not a substitute because there's no indication to the page why the state moved to"suspended"
(did the user pause audio through UA provided hardware controls?) nor is there an indication when playback would be allowed again. The promise returned by"resume"
is not a substitute, because if not immediately rejected, it would resolve at the exact same time as the UA would automatically move the state from"interrupted"
to"running"
in the first scenario, and would reject in the second without indicating to the page that, if they just tried again, things would work fine.Originally posted by @jernoble in #72 (comment)
The text was updated successfully, but these errors were encountered: