-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
131 lines (121 loc) · 3.88 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=yes">
<title>唱吧随机电台</title>
<style type="text/css">
html,
body {
height: 100%;
box-sizing: border-box;
overflow: hidden;
}
div {
box-sizing: border-box;
}
body {
text-align: center;
font-size: 16px;
}
.mt10 {
margin-top: 20px;
}
.button {
width: 100%;
text-align: center;
line-height: 50px;
height: 50px;
font-size: 18px;
}
.from {
position: absolute;
bottom: 0;
width: 100%;
font-size: 12px;
color: #ddd;
}
</style>
</head>
<body>
<audio id="audio" src="http://qiniuuwmp3.changba.com/885402155.mp3" style="width:100%" controls autoplay></audio>
<div><span id="status" class="mt10" style="margin-right: 20px"></span>当前链接:</div>
<div id="now" class="mt10">http://qiniuuwmp3.changba.com/885402155.mp3</div>
<!-- <button id="down" class="mt10 button">下载</button> -->
<button id="play" class="mt10 button">播放</button>
<button id="change" class="mt10 button">切换</button>
<div class="from">资源来源于<a href="//changba.com" target="_blank">《唱吧》</a></div>
<script type="text/javascript">
(function() {
var url = 'http://qiniuuwmp3.changba.com/';
var type = '.mp3'
var min = 680000002;
var num = 580999998;
var audio = document.getElementById('audio');
var now = document.getElementById('now');
var timerNext = null;
var his = [];
function setStatus(t) {
document.getElementById('status').innerHTML = t;
}
function next() {
clearTimeout(timerNext);
var src = parseInt(Math.random() * num) + min;
if (isNaN(src) || his.indexOf(src) > -1) {
next();
return false;
}
his.push(src);
src = url + src + type;
audio.src = src;
now.innerHTML = src;
}
document.getElementById('change').onclick = function() {
next();
};
audio.onerror = function() {
setStatus('出错了');
clearTimeout(timerNext);
timerNext = setTimeout(function() {
next();
}, 2000)
}
audio.onloadstart = function() {
setStatus('开始加载');
}
audio.oncanplay = function() {
setStatus('可以播放了');
setTimeout(function() {
setStatus('');
}, 1000);
}
audio.onended = function() {
setStatus('3秒后自动切换下一首');
clearTimeout(timerNext);
timerNext = setTimeout(function() {
next();
}, 1000);
}
document.getElementById('play').onclick = function() {
audio.play();
};
if (document.getElementById('down')) {
document.getElementById('down').onclick = function() {
window.open(now.innerHTML);
};
}
now.onclick = function() {
var userSelection;
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(this);
selection.removeAllRanges();
selection.addRange(range);
}
};
})();
</script>
</body>
</html>