-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
50 lines (44 loc) · 1.29 KB
/
index.html
File metadata and controls
50 lines (44 loc) · 1.29 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<script>
var playStatus = "paused";
function playPauseAudio() {
var audio = document.getElementById('audio');
if(window.navigator.userAgent.indexOf("hap") >= 0) {
var audioSrc = audio.src;
var message = playStatus === "paused" ? { action: "play", "audioUrl": audioSrc } : { action: "pause" };
system.postMessage(JSON.stringify(message));
return;
}
audio.paused ? audio.play() : audio.pause();
}
function onAudioPlay() {
document.getElementById('playPauseButton').innerHTML = "pause Audio";
playStatus = "playing";
}
function onAudioPause() {
document.getElementById('playPauseButton').innerHTML = "play Audio";
playStatus = "paused";
}
system.onmessage = function(message) {
switch(message) {
case "audio_play":
onAudioPlay();
break;
case "audio_pause":
onAudioPause();
break;
default:
}
}
</script>
</head>
<body class="index">
<audio id="audio" src="https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_700KB.mp3" preload="auto"
onplay="onAudioPlay()" onpause="onAudioPause()"></audio>
<button id="playPauseButton" type="button" onclick="playPauseAudio()">Play audio</button>
</body>
</html>