-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
66 lines (46 loc) · 1.32 KB
/
demo.html
File metadata and controls
66 lines (46 loc) · 1.32 KB
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
<script src="./dist/index.umd.js"></script>
<div id="test"></div>
<div id="clock"></div>
<button id="play">play</button>
<script>
console.log(MediaKit);
const audio = new MediaKit.HTMLAudio('https://actions.google.com/sounds/v1/alarms/bugle_tune.ogg', {});
const media = new MediaKit.Media({
adapter: audio,
duration: 6.233
})
// Tracks don't auto pause and for some reason get into infinite loops.
const track = new MediaKit.Track();
track.addMedia(audio, {
source: {
start: 1,
end: 4
},
target: {
start: 2,
end: 5,
}
})
document.getElementById('test').appendChild(audio.$el);
const player = new MediaKit.Player(media);
const $play = document.getElementById('play');
const $clock = document.getElementById('clock');
player.on('pause', () => {
$play.innerText = 'play';
})
player.on('play', () => {
$play.innerText = 'pause';
})
$play.addEventListener('click', () => {
if (player.isPlaying) {
player.pause();
} else {
player.play();
}
})
const loop = () => {
$clock.innerText = `${player.currentTimeMs}`;
requestAnimationFrame(loop);
};
requestAnimationFrame(loop);
</script>