File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,20 @@ import StartAudioContext from 'startaudiocontext';
2
2
import bowser from 'bowser' ;
3
3
4
4
let AUDIO_CONTEXT ;
5
- if ( ! bowser . msie ) {
6
- AUDIO_CONTEXT = new ( window . AudioContext || window . webkitAudioContext ) ( ) ;
7
5
8
- StartAudioContext ( AUDIO_CONTEXT ) ;
6
+ if ( ! bowser . msie ) {
7
+ /**
8
+ * AudioContext can be initialized only when user interaction event happens
9
+ */
10
+ const event =
11
+ typeof document . ontouchend === 'undefined' ? 'mouseup' : 'touchend' ;
12
+ const initAudioContext = ( ) => {
13
+ document . removeEventListener ( event , initAudioContext ) ;
14
+ AUDIO_CONTEXT = new ( window . AudioContext ||
15
+ window . webkitAudioContext ) ( ) ;
16
+ StartAudioContext ( AUDIO_CONTEXT ) ;
17
+ } ;
18
+ document . addEventListener ( event , initAudioContext ) ;
9
19
}
10
20
11
21
/**
You can’t perform that action at this time.
0 commit comments