-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundeffects.js
104 lines (89 loc) · 2.82 KB
/
soundeffects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const XMark = './sounds/xMark.mp3';
const OMark = './sounds/oMark.mp3';
const win = './sounds/win.mp3';
const tie = './sounds/tie.mp3';
const lose = './sounds/lose.mp3';
const board = './sounds/board.mp3';
const menu = './sounds/menu.mp3';
const swipe = './sounds/swipe.mp3';
const bubble ='./sounds/bubble.mp3'
const audioBlock = document.createElement('div');
const soundEffects = (() => {
const init = () => {
audioBlock.id = 'audioBlock';
document.body.append(audioBlock);
audioBlock.insertAdjacentHTML('beforeend', `
<audio id="xMark-sound"><source src="${XMark}" type="audio/mpeg"></audio>
<audio id="oMark-sound"><source src="${OMark}" type="audio/mpeg"></audio>
<audio id="win-sound"><source src="${win}" type="audio/mpeg"></audio>
<audio id="tie-sound"><source src="${tie}" type="audio/mpeg"></audio>
<audio id="lose-sound"><source src="${lose}" type="audio/mpeg"></audio>
<audio id="board-sound"><source src="${board}" type="audio/mpeg"></audio>
<audio id="menu-sound"><source src="${menu}" type="audio/mpeg"></audio>
<audio id="swipe-sound"><source src="${swipe}" type="audio/mpeg"></audio>
<audio id="bubble-sound"><source src="${bubble}" type="audio/mpeg"></audio>
`);
};
const getAudioBlock = () => audioBlock;
const playXMark = () => {
const xAudio = document.getElementById('xMark-sound');
xAudio.playbackRate = 2;
xAudio.play();
};
const playOMark = () => {
const oAudio = document.getElementById('oMark-sound');
oAudio.playbackRate = 3.5;
oAudio.play();
};
const playWin = () => {
const winAudio = document.getElementById('win-sound');
winAudio.play();
};
const playTie = () => {
const tieAudio = document.getElementById('tie-sound');
tieAudio.play();
};
const playLose = () => {
const loseAudio = document.getElementById('lose-sound');
loseAudio.playbackRate = 1.5;
loseAudio.play();
};
const playBoard = () => {
const boardAudio = document.getElementById('board-sound');
boardAudio.playbackRate = 2;
boardAudio.pause();
boardAudio.currentTime = 0;
boardAudio.play();
};
const playMenu = () => {
const menuAudio = document.getElementById('menu-sound');
menuAudio.pause();
menuAudio.currentTime = 0;
menuAudio.play();
};
const playSwipe = () => {
const swipeAudio = document.getElementById('swipe-sound');
swipeAudio.pause();
swipeAudio.currentTime = 0;
swipeAudio.play();
};
const playBubble = () => {
const bubbleAudio = document.getElementById('bubble-sound');
bubbleAudio.pause();
bubbleAudio.currentTime = 0;
bubbleAudio.play();
};
return {
init,
playXMark,
playOMark,
playWin,
playTie,
playLose,
playBoard,
playMenu,
playSwipe,
playBubble,
getAudioBlock,
};
})();