-
Notifications
You must be signed in to change notification settings - Fork 35
/
audio&video.html
270 lines (242 loc) · 7.55 KB
/
audio&video.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!DOCTYPE html>
<html>
<head>
<title>音频&视频</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="./css/animate.min.css">
<link rel="stylesheet" href="./css/dog.css">
<style type="text/css">
body,
html {
height: 100%;
-webkit-tap-highlight-color: transparent;
max-width: 640px;
max-height: 1136px;
margin: auto;
}
.hide {
display: none;
}
.loading,
.container {
width: 100%;
height: 100%;
left: 0%;
top: 0%;
margin: 0;
border-radius: 0px;
position: relative;
/*background-color: rgba(0, 0, 0, 0.5);*/
}
/*音乐按钮*/
#wraper_music {
position: fixed;
width: 40px;
height: 40px;
top: 10px;
right: 10px;
z-index: 999;
border-radius: 40px;
display: block;
}
#btn_play_music {
width: 40px;
height: 40px;
cursor: pointer;
background-size: 40px 40px;
}
.c_btn_play_music_playing {
background: url(./img/music_playing.png) no-repeat;
-webkit-animation: kf_music_playing 8s linear infinite;
animation: kf_music_playing 8s linear infinite;
}
.c_btn_play_music_paused {
background: url(./img/music_stop.png) no-repeat;
}
@keyframes kf_music_playing {
0% {
-webkit-transform: rotateZ(0deg);
}
100% {
-webkit-transform: rotateZ(360deg);
}
}
@-webkit-keyframes kf_music_playing {
0% {
-webkit-transform: rotateZ(0deg);
}
100% {
-webkit-transform: rotateZ(360deg);
}
}
@media screen and (max-width: 380px) {
#btn_qtcs {
font-size: small;
}
#btn_toumiao {
font-size: small;
}
}
@media screen and (max-width: 320px) {
#btn_qtcs {
font-size: x-small;
}
#btn_toumiao {
font-size: x-small;
}
}
</style>
</head>
<body style="">
<div class="container">
<div id="wraper_music">
<div id="btn_play_music" class="c_btn_play_music_playing"></div>
</div>
<br>
<br>
<br>
<br>
<br>
<audio src="./audio/95484.m4a">
</audio>
<audio style="width: 100%" src="./audio/95484.m4a" controls>
</audio>
<!-- <audio src="./audio/107192078.m4a" autoplay="autoplay" controls>
</audio> -->
<br>
<br>
<br>
<br>
<br>
<video style="width: 100%" src="./video/test.mp4" preload autoplay controls>
</video>
</div>
<script src="./js/jquery.min.js"></script>
<script src="./js/preloadjs.min.js"></script>
<script src="./js/soundjs.min.js"></script>
<script>
//可视区居中显示
var window_height = $(window).height();
if (window_height > 1136) {
var temp_top = ($(window).height() - 1136) / 2;
$('body').css('margin-top', temp_top);
}
//建议使用资源清单,方便管理,如果资源较多,可以考虑独立出json文件,脚本自动生成。
var manifest = [{
id: '告白气球',
src: './audio/107192078.m4a'
}, {
id: '一生有你',
src: './audio/95484.m4a'
}, ]
var queue = new createjs.LoadQueue();
//SoundJS默认用的是复杂的Web Audio接口,这会导致加载音频变慢,所以显示注册使用html的audio即可
createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
//如果需要加载音频,需要注册SoundJs插件
queue.installPlugin(createjs.Sound);
queue.on("complete", function() {
//createjs.Sound.play("告白气球");
music_player = new Player($('#btn_play_music'), "./audio/107192078.m4a");
}, this);
queue.on("progress", function(event) {
console.log("Progress:", queue.progress, event.progress);
});
//设置并列加载,否则每次只加载一个,太耗时
queue.setMaxConnections(5);
queue.maintainScriptOrder = true;
queue.loadManifest(manifest);
//---------start播放器代码---------
function Player(el, src) {
this.el = el;
this.isPlay = true;
if (src == undefined) {
src = '';
}
this.init(src);
}
Player.prototype = {
init: function(src) {
var _this = this,
attr = {
loop: true,
preload: "auto",
autoplay: true,
src: src
};
this._audio = new Audio;
for (var i in attr) {
attr.hasOwnProperty(i) && i in this._audio && (this._audio[i] = attr[i]);
}
this.inited = false;
$(this._audio).on('durationchange', function() {
// 播放加载
if (_this._audio.duration > 1) {
_this.inited = true;
}
});
$(this._audio).on('ended', function() {
// 播放结束
_this._audio.currentTime = 0;
_this.isPlay = false;
_this._play();
});
if (src != '') {
this._audio.load();
}
if (typeof this.el !== 'string') {
this.el.on('click', function() {
_this._play();
});
}
},
_load: function() {
this._audio.load();
},
_src: function(src) {
this._audio['src'] = src;
},
_isplay: function() {
return this.isPlay;
},
_play: function() {
if (!this.isPlay) {
this._audio.play();
if (typeof this.el !== 'string') {
this.el.removeClass('c_btn_play_music_paused');
this.el.addClass('c_btn_play_music_playing');
}
} else {
this._audio.pause();
if (typeof this.el !== 'string') {
this.el.removeClass('c_btn_play_music_playing');
this.el.addClass('c_btn_play_music_paused');
}
}
this.isPlay = !this.isPlay;
},
_playOn: function() {
this._audio.play();
if (typeof this.el !== 'string') {
this.el.removeClass('c_btn_play_music_paused');
this.el.addClass('c_btn_play_music_playing');
}
this.isPlay = true;
},
_playOff: function() {
this._audio.pause();
if (typeof this.el !== 'string') {
this.el.removeClass('c_btn_play_music_playing');
this.el.addClass('c_btn_play_music_paused');
}
this.isPlay = false;
},
_volume: function(num) {
this._audio.volume = num;
}
}
//---------end播放器代码---------
</script>
</body>
</html>