Skip to content

Commit f6aea92

Browse files
committed
add getAudioContext example
1 parent 332db54 commit f6aea92

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/audiocontext.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,33 @@ define(function () {
1010
* 'http://webaudio.github.io/web-audio-api/'>Web Audio API
1111
* </a>.</p>
1212
*
13+
* <p>Some browsers require users to startAudioContext
14+
* with a user gesture, such as touchStarted in the example below.</p>
15+
*
1316
* @method getAudioContext
1417
* @return {Object} AudioContext for this sketch
18+
* @example
19+
* <div><code>
20+
* function draw() {
21+
* background(255);
22+
* textAlign(CENTER);
23+
*
24+
* if (getAudioContext().state !== 'running') {
25+
* text('click to start audio', width/2, height/2);
26+
* } else {
27+
* text('audio is enabled', width/2, height/2);
28+
* }
29+
* }
30+
*
31+
* function touchStarted() {
32+
* if (getAudioContext().state !== 'running') {
33+
* getAudioContext().resume();
34+
* }
35+
* var synth = new p5.MonoSynth();
36+
* synth.play('A4', 0.5, 0, 0.2);
37+
* }
38+
*
39+
* </div></code>
1540
*/
1641
p5.prototype.getAudioContext = function() {
1742
return audiocontext;

0 commit comments

Comments
 (0)