搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
我家自动化
这个屌丝很懒,什么也没留下!
关注作者
热门标签
jquery
HTML
CSS
PHP
ASP
PYTHON
GO
AI
C
C++
C#
PHOTOSHOP
UNITY
iOS
android
vue
xml
爬虫
SEO
LINUX
WINDOWS
JAVA
MFC
CEF3
CAD
NODEJS
GIT
Pyppeteer
article
热门文章
1
前端如何将项目部署到服务器(Nginx)_前端部署到nginx
2
STM32CubeMX环境下利用STM32F103RCT6 单片机的UART5口实现RS232串口通信。_stm32f103rct6 stm32cubemax 485
3
Keil开发STM32单片机项目的三种方式_keil stm32
4
ElasticSearch 索引创建_elasticsearch 创建索引
5
nginx快速入门
6
thinkphp6、thinkphp5.0 使用think-queue实现普通队列和延迟队列_thinkphp5.0 队列
7
Git 分布式版本控制系统_分布式版本控制系统git
8
tar命令中--exclude参数详解_tar exclude
9
人工智能导论(6)——机器学习(Machine Learning)_机器学习 人工智能导论
10
基于javaweb的家居购物商城系统(java+html+jdbc+mysql)_javaweb购物商城项目源码
当前位置:
article
> 正文
HTML5 CSS3实战——自定义音乐播放器(一)_
作者:我家自动化 | 2024-03-16 06:15:36
赞
踩
// 播放器
var
Player; Player = {
// 歌曲路径
path:
'video/'
, imgPath:
'images/music/'
,
// 歌曲数据
data:
null
, imgs:
null
,
// 当前播放歌曲的 索引
currentIndex: -
1
,
// 播放器元素jquery对象
$audio: $(
'#audio'
),
// 歌曲列表
$mList: $(
'#playlist'
),
//正在播放的歌曲
$rmusic: $(
'#rmusic'
), $cover: $(
'#imcover'
),
// 初始化 数据
init:
function
()
{
// 数据一般来自服务器端,通过ajax 加载数据,这里是模拟
//歌曲的数据
Player.data = [
'GlassySky.mp3'
,
'回梦游仙.mp3'
,
'unravel.mp3'
,
'一直很安静.mp3'
];
//封面的数据
Player.imgs = [
'GlassySky.jpg'
,
'回梦游仙.png'
,
'unravel.jpg'
,
'一直很安静.png'
]; Player.$rmusic.html(Player.data[Player.currentIndex]);
//初始化
var
mhtml =
''
;
var
len = Player.data.length;
//初始化歌曲列表
for
(
var
i =
0
; i < len; i++) { mhtml +=
'<li value="'
+ i +
'"><a >'
+ Player.data[i] +
'</a></li>'
; } Player.$mList.html(mhtml);
//初始化专辑封面
Player.$cover.attr(
"src"
, Player.imgPath+Player.imgs[
0
]); },
// 就绪
ready:
function
()
{
// 控制
Player.audio = Player.$audio.get(
0
); Player.$rmusic.html(Player.data[Player.currentIndex]);
// 播放
$(
'#btn-play'
).click(
function
()
{
Player.audio.play();
if
(Player.currentIndex == -
1
) { $(
'#btn-next'
).click(); } });
// 暂停
$(
'#btn-pause'
).click(
function
()
{
Player.audio.pause(); });
// 下一曲
$(
"#forward"
).click(
function
()
{
if
(Player.currentIndex == -
1
) { Player.currentIndex =
0
; }
else
if
(Player.currentIndex == (Player.data.length -
1
)) { Player.currentIndex =
0
; }
else
{ Player.currentIndex++; }
var
currentMusic=Player.data[Player.currentIndex]; currentMusic = currentMusic.substring(
0
,currentMusic.indexOf(
'.'
)); console.log(
"Player.currentIndex : "
+ Player.currentIndex); Player.audio.src = Player.path + Player.data[Player.currentIndex]; Player.$rmusic.html(currentMusic); Player.$cover.attr(
"src"
, Player.imgPath+Player.imgs[Player.currentIndex]); Player.audio.play(); });
// 上一曲
$(
'#backward'
).click(
function
()
{
if
(Player.currentIndex == -
1
) { Player.currentIndex =
0
; }
else
if
(Player.currentIndex ==
0
) { Player.currentIndex = (Player.data.length -
1
); }
else
{ Player.currentIndex--; }
var
currentMusic=Player.data[Player.currentIndex]; currentMusic = currentMusic.substring(
0
,currentMusic.indexOf(
'.'
)); Player.audio.src = Player.path + Player.data[Player.currentIndex]; Player.$cover.attr(
"src"
, Player.imgPath+Player.imgs[Player.currentIndex]); Player.$rmusic.html(currentMusic); Player.audio.play(); });
// 单曲循环
$(
'#btn-loop'
).click(
function
()
{
console.log(
"Player.currentIndex :"
, Player.currentIndex); Player.audio.onended =
function
()
{
Player.audio.load(); Player.audio.play(); }; });
// 顺序播放
$(
'#sequence'
).click(
function
()
{
console.log(
"Player.currentIndex :"
, Player.currentIndex); Player.audio.onended =
function
()
{
$(
'#btn-next'
).click(); }; });
// 随机播放
$(
'#randoms'
).click(
function
()
{
Player.audio.onended =
function
()
{
var
i =
parseInt
((Player.data.length -
1
) *
Math
.random()); alert(i); playByMe(i); }; });
// 播放指定歌曲
function
playByMe
(i)
{
i=
parseInt
(i); Player.audio.src = Player.path + Player.data[i]; Player.audio.play(); Player.currentIndex = i; Player.$rmusic.html(Player.data[Player.currentIndex]); Player.$cover.attr(
"src"
, Player.imgPath+Player.imgs[Player.currentIndex]); }
// 歌曲被点击
$(
'#playlist li'
).click(
function
()
{
$(
this
).find(
'a'
).find(
'i'
).remove(); $(
this
).find(
'a'
).css(
"color"
,
"#26C5CB"
); $(
this
).find(
'a'
).prepend(
"<i class=\"fa fa-play\" style=\"margin-right:4px;\"></i>"
); $(
this
).siblings().find(
'a'
).css(
"color"
,
"#ffffff"
); $(
this
).siblings().find(
'a'
).find(
'i'
).remove();
var
i =
parseInt
($(
this
).attr(
'value'
)); playByMe(i);
/*style="color:#26C5CB;"*/
}); },
//循环播放
loop:
function
()
{
Player.audio.onended =
function
()
{
if
(Player.currentIndex == -
1
) { Player.currentIndex =
0
; }
else
if
(Player.currentIndex == (Player.data.length -
1
)) { Player.currentIndex =
0
; }
else
{ Player.currentIndex++; }
var
currentMusic=Player.data[Player.currentIndex]; currentMusic = currentMusic.substring(
0
,currentMusic.indexOf(
'.'
)); console.log(
"Player.currentIndex : "
+ Player.currentIndex); Player.audio.src = Player.path + Player.data[Player.currentIndex]; Player.$cover.attr(
"src"
, Player.imgPath+Player.imgs[Player.currentIndex]); Player.$rmusic.html(currentMusic); Player.audio.play(); } } }; Player.init(); Player.ready(); Player.loop(); }); audio.controls =
false
; audio.addEventListener(
'timeupdate'
,
function
()
{
updateProgress(); },
false
);
function
togglePlayPause
()
{
if
(audio.paused || audio.ended) { playpause.title =
"Pause"
; playpause.innerHTML =
'<i class="fa fa-pause fa-3x"></i>'
; audio.play(); }
else
{ playpause.title =
"Play"
; playpause.innerHTML =
'<i class="fa fa-play fa-3x"></i>'
; audio.pause(); } }
function
setVolume
()
{
audio.volume = volume.value; }
//更新进度条
function
updateProgress
()
{
var
percent =
Math
.floor((
100
/ audio.duration) * audio.currentTime); progress.value = percent;
var
canvas = document.getElementById(
'progress'
);
var
context = canvas.getContext(
'2d'
);
var
centerX = canvas.width /
2
;
var
centerY = canvas.height /
2
;
var
radius =
150
;
var
circ =
Math
.PI *
2
;
var
quart =
Math
.PI /
2
;
var
cpercent = percent /
100
;
/* current percent */
context.beginPath(); context.arc(centerX, centerY, radius,
0
, ((circ) * cpercent),
false
); context.lineWidth =
10
; context.strokeStyle =
'#26C5CB'
; context.stroke();
if
(audio.ended) resetPlayer(); }
//重置播放器
function
resetPlayer
()
{
audio.currentTime =
0
; context.clearRect(
0
,
0
,canvas.width,canvas.height); playpause.title =
"Play"
; playpause.innerHTML =
'<i class="fa fa-play fa-3x"></i>'
; }
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
由于时间关系,所以歌词列表的动态显示功能还没做。这需要解析歌词的格式。准备在下次完成歌词列表功能。
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/w/我家自动化/article/detail/247622
推荐阅读
article
共"+pag" href="/w/凡人多烦事01/article/detail/227959" target="_blank">jQuery静态分页_
page
html+
=
"
class
=
'
page
_last'>共
"
+pag...
共"+pag" href="/w/凡人多烦事01/article/detail/227959" target="_blank">html<script src
=
"
https://cdn.staticfile.org/jquery/2.2.4/...
赞
踩
article
android
使用etc1,
ETC1
Class
...
ETC1
Class
DefinitionAssembly:Mono.Android.dllMethods for enc...
赞
踩
article
arc
gis
arcmap
增加
经
纬度
属性,
label
度分秒
经
纬度
十进制
经
纬度
_
gis
中属性表中...
arc
gis
arcmap
增加
经
纬度
属性,
label
度分秒
经
纬度
十进制
经
纬度
点.shp文件右击----prope...
赞
踩
article
实时
视频
直播
客户端
技术盘点:Native、
HTML5
、
WebRTC
、微信小程序_
native
终端...
实时
视频
直播
客户端
技术盘点:Native、
HTML5
、
WebRTC
、微信小程序_
native
终端
native
终端 ...
赞
踩
article
php
class
video
,
微信小程序
video
组件详解...
这篇文章主要介绍了微信小程序
video
组件详解的相关资料
,
需要的朋友可以参考下主要属性:效果图:ml:1.播放网络视频...
赞
踩
article
错误处理:
could
not
find
the
main
class
,
Program
will
e...
原地址:http://blog.csdn.net/xiaogugood/article/details/82841401...
赞
踩
article
Could
not
resolve
type
alias
''. Cause:
java
.
lang
...
报错原因一般都在mapper的映射文件里面对于select的语句,一定要注意返回类型的选择,要写resultMap="B...
赞
踩
article
ACFNet
:用于语义分割的注意类特征网络_
attentional
class
feature
ne...
原名:
ACFNet
: Attentional Class Feature Network for Semantic Se...
赞
踩
article
background
引起错误:Error
inflating
class
_
service
error
...
具体错误: java.lang.RuntimeException: Unable to start activity C...
赞
踩
article
安卓开发——
Error
inflating
class
******(
com
.
example
.pul...
Error
inflating
class
******(
com
.
example
.pull_to_refresh.Pul...
赞
踩
article
UVCCamera项目中usbCameraTest运行时报错--
java
.
lang
.RuntimeE...
报错详情:Process:
com
.serenegiant.usbcameratest, PID: 4409
java
.l...
赞
踩
article
Error
inflating
class
com.
baidu
.
mapapi
.map.
MapView
...
看了网上很多解决方法,都没能解决问题,结果SDKInitializer.initialize(getApplicatio...
赞
踩
article
【解决
TabLayout
报错】Error
inflating
class
com.
google
.an...
解决
TabLayout
出现的一个奇怪报错_error
inflating
class
com.
google
.androi...
赞
踩
article
Android
TextureView 报错:Error
inflating
class
andr...
项目接入视频播放,在
Android
6.0手机上运行没问题,结果在
Android
10.0手机上进入播放界面直接闪退。报错...
赞
踩
article
已解决 Error inflating
class
com.
google
.
android
.mater...
CoordinatorLayout、
AppBarLayout
_error inflating
class
com.go...
赞
踩
article
Error inflating
class
com.google.
android
.
material
....
在xml里面使用
MaterialButton
的时候报错,报错信息如下: Caused by:
android
.view....
赞
踩
article
Error inflating
class
com
.
facebook
.
drawee
.
view
.Sim...
刚刚遇到的一个小问题,在引用 ‘
com
.
facebook
.fresco:fresco:0.6.0’ 库后,在布局中使用 ...
赞
踩
article
百度地图
Android
SDK报错:Error
inflating
class
com
.
baidu
....
在自己的开发的
Android
应用中调用百度地图
Android
SDK,发生运行时错误:Error
inflating
c...
赞
踩
article
解决Error inflating
class
com
.
google
.
android
.materia...
请确保在混淆规则文件(通常是 proguard-rules.pro 文件)中添加以下规则,以避免混淆
com
.googl...
赞
踩
article
Error
inflating
class
com
.baidu.
map
api.
map
.MapView...
java.lang.RuntimeException: Unable to start activity Compone...
赞
踩
相关标签
android 使用etc1
音视频
webrtc
视频编解码
实时音视频
android studio
php class video
非空间上下文聚合
语义分割
android
uvccamera
百度地图
Android
app
安卓
Fresco