-
Notifications
You must be signed in to change notification settings - Fork 0
/
audioskip.html
94 lines (71 loc) · 2.38 KB
/
audioskip.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
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
<html>
<head>
<style>
.buttonStyling {
font-size:20px;
display:block;
width:100px;
}
</style>
</head>
<body>
<script>
function playTimestamp(time) {
var myAudio=document.getElementById("sound");
myAudio.currentTime = time;
//myAudio.play();
}
var times = [20, 40, 70, 90];
function addButton(times) {
document.getElementById("buttons").innerHTML = "";
times.forEach( function (t) {
var button= document.createElement('button');
button.type = "button";
button.appendChild(document.createTextNode(secondsminutes(t)));
button.setAttribute("onclick", "playTimestamp("+t+")");
document.getElementById("buttons").appendChild(button);
button.classList.add("buttonStyling");
});
audioUpload();
}
function secondsminutes(t) {
var seconds = t % 60;
var minutes = Math.floor(t/60);
var hours = Math.floor(minutes/60);
minutes = minutes % 60;
var strSec = seconds;
var strMin = minutes;
var strHours = hours;
if (hours.toString().length === 1) {
strHours = "0" + hours.toString();
}
if (minutes.toString().length === 1) {
strMin = "0" + minutes.toString();
}
if (seconds.toString().length === 1) {
strSec = "0" + seconds.toString();
}
var display = strHours + ":" + strMin + ":" + strSec;
return display;
}
function clearButtons() {
document.getElementById("buttons").innerHTML = "";
document.getElementById("sound").setAttribute("currentTime", 0);
}
function audioUpload() {
var audio = document.getElementById("upload").files[0];
var reader = new FileReader();
reader.onload = function(e) {
document.getElementById("sound").src = e.target.result;
document.getElementById("sound").controls = "controls";
}
reader.readAsDataURL(audio);
}
</script>
<audio id="sound" src="https://ia801309.us.archive.org/5/items/eubanks_elizabeth_01/eubanks_elizabeth_01.mp3" controls="controls"> </audio>
<button id="upload" type="submit" onclick="addButton(times)">Submit</button>
<button type="reset" onclick="clearButtons()">reset</button>
<div id="buttons">
</div>
</body>
</html>