Skip to content

Commit e40539f

Browse files
gabrielsanbritohoch
authored andcommitted
Adding algo steps for the interrupted state
1 parent 080699d commit e40539f

1 file changed

Lines changed: 81 additions & 9 deletions

File tree

index.bs

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,26 +1969,40 @@ Methods</h4>
19691969

19701970
1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=fully active=] then return [=a promise rejected with=] "{{InvalidStateError}}" {{DOMException}}.
19711971

1972-
1. Let <var>promise</var> be a new Promise.
1972+
2. Let <var>promise</var> be a new Promise.
19731973

1974-
2. If the {{[[control thread state]]}} on the
1975-
{{AudioContext}} is <code>closed</code> reject the
1974+
3. If the {{[[control thread state]]}} on the
1975+
{{AudioContext}} is <code>closed</code> or <code>interrupted</code> reject the
19761976
promise with {{InvalidStateError}}, abort these steps,
19771977
returning <var>promise</var>.
19781978

1979-
3. Set {{[[suspended by user]]}} to <code>false</code>.
1979+
4. Set {{[[suspended by user]]}} to <code>false</code>.
1980+
1981+
4. If the {{BaseAudioContext/state}} attribute of the {{AudioContext}} is "{{AudioContextState/suspended}}" and the {{[[control thread state]]}} on the
1982+
{{AudioContext}} is <code>interrupted</code>:
19801983

1981-
4. If the context is not <a>allowed to start</a>, append
1984+
1. <a href="https://html.spec.whatwg.org/multipage/media.html#queue-a-media-element-task">
1985+
queue a media element task</a> to execute the following steps:
1986+
1987+
1. Set the {{BaseAudioContext/state}} attribute of the {{AudioContext}} to "{{AudioContextState/interrupted}}".
1988+
1989+
2. [=Queue a media element task=] to [=fire an event=] named
1990+
{{BaseAudioContext/statechange}} at the {{AudioContext}}.
1991+
1992+
2. Reject the promise with {{InvalidStateError}}, abort these steps,
1993+
returning <var>promise</var>.
1994+
1995+
5. If the context is not <a>allowed to start</a>, append
19821996
<var>promise</var> to {{BaseAudioContext/[[pending promises]]}} and
19831997
{{AudioContext/[[pending resume promises]]}} and abort these steps, returning
19841998
<var>promise</var>.
19851999

1986-
5. Set the {{[[control thread state]]}} on the
2000+
6. Set the {{[[control thread state]]}} on the
19872001
{{AudioContext}} to <code>running</code>.
19882002

1989-
6. <a>Queue a control message</a> to resume the {{AudioContext}} with <var>promise</var>.
2003+
7. <a>Queue a control message</a> to resume the {{AudioContext}} with <var>promise</var>.
19902004

1991-
7. Return <var>promise</var>.
2005+
8. Return <var>promise</var>.
19922006
</div>
19932007

19942008
<div id="context-resume" algorithm="run a control message in AudioContext">
@@ -4078,7 +4092,7 @@ Methods</h4>
40784092
scheduled parameter changes with times greater than or equal to
40794093
{{AudioParam/cancelAndHoldAtTime()/cancelTime!!argument}}. However, in addition, the automation
40804094
value that would have happened at {{AudioParam/cancelAndHoldAtTime()/cancelTime!!argument}} is
4081-
then proprogated for all future time until other automation
4095+
then propagated for all future time until other automation
40824096
events are introduced.
40834097

40844098
The behavior of the timeline in the face of
@@ -11968,6 +11982,64 @@ running the algorithm for an {{AudioNode}}, using an <a>input
1196811982
buffer</a> and the value(s) of the {{AudioParam}}(s) of this
1196911983
{{AudioNode}} as the input for this algorithm.
1197011984

11985+
<h3 id="interruption-handling">Handling an interruption on the {{AudioContext}}</h3>
11986+
11987+
The {{AudioContext}} |audioContext| performs the following steps on the <a>rendering thread</a> when an interruption happens.
11988+
11989+
1. If the |audioContext|'s {{[[rendering thread state]]}} is <code>closed</code> or <code>interrupted</code>:
11990+
11991+
1. Abort these steps.
11992+
11993+
1. If the |audioContext|'s {{[[rendering thread state]]}} is <code>running</code>:
11994+
11995+
1. Attempt to <a>release system resources</a>.
11996+
11997+
1. [=Queue a media element task=] to execute the following steps:
11998+
11999+
1. Set the |audioContext|'s {{[[control thread state]]}} to <code>interrupted</code>.
12000+
12001+
1. [=Fire an event=] named {{BaseAudioContext/statechange}} at the |audioContext|.
12002+
12003+
1. If the |audioContext|'s {{[[rendering thread state]]}} is <code>suspended</code>:
12004+
12005+
1. [=Queue a media element task=] to execute the following steps:
12006+
12007+
1. Set the |audioContext|'s {{[[control thread state]]}} to <code>interrupted</code>.
12008+
12009+
1. Set the |audioContext|'s {{[[rendering thread state]]}} to <code>interrupted</code>.
12010+
12011+
Note: If the {{AudioContext}} is <code>suspended</code> a {{BaseAudioContext/statechange}} event is not fired for privacy reasons to avoid over-sharing user activity - e.g. when a phone call comes in or when the screen gets locked.
12012+
12013+
The {{AudioContext}} |audioContext| performs the following steps on the <a>rendering thread</a> when the interruption ends.
12014+
12015+
1. If the |audioContext|'s {{[[rendering thread state]]}} is not <code>interrupted</code>:
12016+
12017+
1. Abort these steps.
12018+
12019+
1. If the |audioContext|'s {{[[rendering thread state]]}} was <code>running</code> before the interruption or if the the |audioContext|'s {{[[rendering thread state]]}} was <code>suspended</code> and {{AudioContext/resume}} was called during the interruption:
12020+
12021+
1. Attempt to <a href="#acquiring">acquire system resources</a>.
12022+
12023+
2. Set the {{[[rendering thread state]]}} on the {{AudioContext}} to <code>running</code>.
12024+
12025+
3. Start <a href="#rendering-loop">rendering the audio graph</a>.
12026+
12027+
4. [=Queue a media element task=] to execute the following steps:
12028+
12029+
1. If the {{BaseAudioContext/state}} attribute of the {{AudioContext}} is not already "{{AudioContextState/running}}":
12030+
12031+
1. Set the |audioContext|'s {{[[control thread state]]}} to <code>running</code>.
12032+
12033+
1. [=Fire an event=] named {{BaseAudioContext/statechange}} at the |audioContext|.
12034+
12035+
1. If the |audioContext|'s {{[[rendering thread state]]}} was <code>suspended</code> before the interruption:
12036+
12037+
1. Set the {{[[rendering thread state]]}} on the {{AudioContext}} to <code>suspended</code>.
12038+
12039+
2. [=Queue a media element task=] to execute the following steps:
12040+
12041+
1. Set the |audioContext|'s {{[[control thread state]]}} to <code>suspended</code>.
12042+
1197112043
<h3 id="error-handling-on-a-running-audio-context">
1197212044
Handling an error from System Audio Resources on the {{AudioContext}}</h3>
1197312045

0 commit comments

Comments
 (0)