Skip to content

Commit 982c84c

Browse files
committed
Defer loading of audioContext until user has interacted with page
1 parent 95e445b commit 982c84c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

apps/fretonator-web/src/app/common/playback/note-playback.service.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ const SYNTH_PLAY_DURATION = 2000;
1010
export class NotePlaybackService {
1111
private context: AudioContext;
1212

13-
constructor() {
14-
try {
15-
// Feature sniff for web audio API
16-
this.context = new (window.AudioContext || window['webkitAudioContext']);
17-
} catch (e) {
18-
// No browser support :(
19-
}
20-
}
13+
constructor() {}
2114

2215
playNote(stringName, fret) {
23-
if (this.context) {
16+
if (!this.context) {
17+
try {
18+
// Feature sniff for web audio API
19+
this.context = new (window.AudioContext || window['webkitAudioContext']);
20+
} catch (e) {
21+
// No browser support :(
22+
}
23+
}
24+
if(this.context){
2425
const noteFrequency = this.getFrequency(stringName, fret);
2526
this.pluckString(noteFrequency);
2627
}

0 commit comments

Comments
 (0)