Closed Bug 1489278 Opened 6 years ago Closed 6 years ago

Show doorhanger when web audio is trying to autoplay

Categories

(Core :: Audio/Video: Playback, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla64
Tracking Status
firefox64 --- fixed

People

(Reporter: alwu, Assigned: alwu)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

We should show the doorhanger for web audio as well when the web audio tries to autoplay, and then we would allow it to autoplay if getting user's approval.
Priority: -- → P3
The timing of showing doorhanger for media element is when audible autoplay is trying to start playing. However, it seems to me that the timing of showing doorhanger doesn't fit in well in the design of web audio, because web audio doesn't have the entry point for "starting playback".

Although AudioContext has resume()/suspend() functions which are not used to indicate the playback start of end, more like to indicate that the web audio engine has started.

The resume() will change AudioContext into `running` state which means Audio Context now starts processing input, but it doesn't mean that we have fed AudioContext any audible input yet. 

---

So, the question is "When should we show the doorhanger for web audio?"

1. When AudioContext is created

From the purpose of doorhanger, it violates the timing of showing the doorhanger. Creating audio context doesn't mean that the web audio is trying to play audible sound. 

From user pespective, it would cause lots unnecessary doorhanger, it would make user feel confused. 


2. Just before the destination node get the audible input

It's a good timing to show doorhanger, but we don't want user to hear any sound before user approve the doorhanger. Therefore, we must suspend AudioContext and resume AudioContext after get the user's approval

That causes two issues,

(1) AudioContext was changed from "running" -> "suspended" -> "running"
We have two extra state transitions here, and it apparently is not a spec-defined behavior. Not sure whether it would break any sites. I also don't like this redundant transition.

(2) Audio leaking 
I haven't tested that, but I guess the audio might leak in this situation. We handle input buffer in MSG thread, but if we want to suspend AudioContext, we need to go back to mainthread to call AudioContext.suspend() and wait for the operation sending to MSG thread. Within this period, the audio input might has been sent to audio device.

---

If possible, I would prefer to keep AudioContext in `suspened` state in the beginning, and then show doorhanger when AudioContext's destination node has connected with some input nodes which have called start or is sending audilbe input to the destionation node.

Paul, could you give me any suggestion here?

Thank you.
Flags: needinfo?(padenot)
In addition, here is a second questions, 
"should we automatically resume AudioContext which was suspended by blocking-autoplay when user activate the page?"
The spec is pretty clear. We need to not do the initial "suspended" -> "running" transition, and show the door-hanger instead.

Then, when a uses accepts the door-hanger, this transition happens.

Alternatively, the door-hanger hides if `resume()` is called from a touch/click handler, and the AudioContext switches to "running".

We can then implement other behaviour if we decide this is not sufficient.
Flags: needinfo?(padenot)
Depends on: 1490074
In the ideal situation, sites should create AudioContext only when sites are going to produce
sound, so we would show doorhanger to ask users whether they want to allow autoplay.

We delay the AudioContext's state transition from `suspended` to `running` until
(1) user click 'Allow' button in doorhanger
(2) user interact with sites, and then AudioContext calls resume() again
Comment on attachment 9008240 [details]
Bug 1489278 - part1 : show doorhanger when create AudioContext

Paul Adenot (:padenot) has approved the revision.
Attachment #9008240 - Flags: review+
Comment on attachment 9008241 [details]
Bug 1489278 - part2 : add test.

Paul Adenot (:padenot) has approved the revision.
Attachment #9008241 - Flags: review+
Pushed by alwu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4cf5ee8d6112
part1 : show doorhanger when create AudioContext r=padenot
https://hg.mozilla.org/mozilla-central/rev/4cf5ee8d6112
https://hg.mozilla.org/mozilla-central/rev/2477110ccfba
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Blocks: 1491475
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: