@@ -20,8 +20,10 @@ const ac = p5sound.audiocontext;
20
20
* @example
21
21
* <div><code>
22
22
* let mic, recorder, soundFile;
23
- * // mousePress will increment from state = 0 (Record), to 1(Stop), to 2(Play)
24
- * let state = 0;
23
+ * // keeps record if recording is started
24
+ * let isRecordingStarted = false;
25
+ * // keeps record if the recorded result is played
26
+ * let isResultPlayed = false;
25
27
*
26
28
* function setup() {
27
29
* let cnv = createCanvas(100, 100);
@@ -49,7 +51,7 @@ const ac = p5sound.audiocontext;
49
51
* // ensure audio is enabled
50
52
* userStartAudio();
51
53
*
52
- * if (state === 0 ) {
54
+ * if (!isRecordingStarted && !isResultPlayed ) {
53
55
* // make sure user enabled the mic by prompting to enable their browser mic
54
56
* // start recording after the mic is enabled
55
57
* mic.start(function() {
@@ -58,10 +60,10 @@ const ac = p5sound.audiocontext;
58
60
*
59
61
* background(255,0,0);
60
62
* text('Recording!', width/2, height/2);
61
- * state++ ;
63
+ * isRecordingStarted = true ;
62
64
* });
63
65
* }
64
- * else if (state === 1 ) {
66
+ * else if (isRecordingStarted && !isResultPlayed ) {
65
67
* background(0,255,0);
66
68
*
67
69
* // stop recorder and
@@ -71,10 +73,10 @@ const ac = p5sound.audiocontext;
71
73
* mic.dispose();
72
74
*
73
75
* text('Done! Tap to play and download', width/2, height/2, width - 20);
74
- * state++ ;
76
+ * isResultPlayed = true ;
75
77
* }
76
78
*
77
- * else if (state === 2 ) {
79
+ * else if (isRecordingStarted && isResultPlayed ) {
78
80
* soundFile.play(); // play the result!
79
81
* save(soundFile, 'mySound.wav');
80
82
* }
0 commit comments