blob: 293f6cadc484fa57c53bd8f6ad52d65df750826d (
plain)
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
|
<!DOCTYPE HTML>
<html>
<body>
<script type="application/javascript;version=1.7">
var audio = new Audio();
audio.src = "audio.ogg";
audio.loop = true;
function assert(aVal, aMessage) {
return (!aVal) ? ok(false, aMessage) : 0;
}
function ok(aVal, aMsg) {
alert((!!aVal ? "OK" : "KO") + ", " + aMsg);
}
function info(aMsg) {
alert("INFO" + ", " + aMsg);
}
function randomSeeking() {
var seekingPosition = Math.random() * audio.duration;
assert(seekingPosition < audio.duration, "Seeking position out of range!")
audio.currentTime = seekingPosition;
audio.onseeked = () => {
audio.onseeked = null;
location.hash = '#idle';
ok(true, "Seeking complete, position = " + seekingPosition);
};
}
function runCommands()
{
switch(location.hash) {
case '#play':
audio.play();
audio.onplay = () => {
audio.onplay = null;
info("Start playing, duration = " + audio.duration);
};
break;
case '#seeking':
randomSeeking();
break;
case '#pause':
audio.pause();
audio.onpause = () => {
audio.onpause = null;
ok(true, "Stop playing.");
};
break;
case '#idle':
break;
default :
ok(false, "Undefined command!");
}
}
window.addEventListener('hashchange', runCommands);
</script>
</body>
</html>
|