-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (54 loc) · 1.96 KB
/
index.html
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
<!DOCType HTML>
<html>
<body>
<p>Click the button to get the exact length (duration) of the audio, in seconds.</p>
<button onclick="playAfter()">Plays them in sequence</button>
<button onclick="play_drum_from_file()">Play from files</script>
<button onclick="play_from_file('sound_clips/basic_drum.wav')">Play drum with function</script>
<button onclick="play_from_file('sound_clips/guitar_loops.wav')">Play guitar with function</script>
<button onclick="play_from_file('sound_clips/constant_bass.wav')">Play bass with function</script>
<button onclick="play_from_file('sound_clips/funky_guitar.wav')">Play funcky guitar with function</script>
<button onclick="play_from_file('sound_clips/alto_sax.wav')">Play Sax with function</script>
<button onclick="play_in_sequence('sound_clips/basic_drum.wav', 'sound_clips/alto_sax.wav');">Play in sequence function</script>
<script>
function play_guitar(){
var guit = document.getElementById("guitar");
guit.play()
}
function play_drum() {
var dru = document.getElementById("drum");
dru.play()
}
function play_from_file(filename){
var clip = new Audio(filename);
clip.play()
}
function play_drum_from_file(){
var drum = new Audio('basic_drum.wav');
var guitar = new Audio('guitar_loops.wav');
setTimeout(drum.play(), 1000);
}
function play_in_sequence(...filenames){
// array to store all the audio files
var audios = new Array()
// Loop through the filenames and create an audio object
for (i=0; i<filenames.length; i++){
var audio = new Audio(filenames[i]);
audios.push(audio)
}
// loop through all the audios and play them
for (i=0; i<filenames.length; i++){
var play = setTimeout(audios[i].play(), 5000);
clearTimeout(play);
}
}
function playAfter(){
//var guitar_time = document.getElementById("guitar").duration;
//var drum_time = document.getElementById("drum").duration;
playing_guitar = setTimeout(play_guitar(), 1000);
clearTimeout(playing_guitar)
setTimeout(play_drum(), 7000)
}
</script>
</body>
</html>