-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
935 lines (905 loc) · 35 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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Music Player</title>
<!-- <style>
div{
outline: 1px split #fff;
}
.main {
height: 450px;
}
.main-lrc {
height: 450px;
width: 550px;
margin: 0 auto;
border: 1px solid #333;
}
.lrc {
height: 350px;
text-align: center;
overflow: auto;
}
.on {
color: blue;
}
.m-player {
width: 900px;
height: 47px;
left: 50%;
margin: 0 auto;
background-color: #333;
}
.btns {
width: 137px;
margin: 0px 18px 0 30px;
/* outline: solid 1px #ccc; */
height: 47px;
background-color: #333;
float: left;
border-right: none;
}
#id-music-pre{
background-position: 0 -130px;
}
#id-music-pre:hover{
background-position: -30px -130px;
}
.btns #id-audio-player {
background-position: 0 -204px;
width: 36px;
height: 36px;
margin-top: 5.5px;
}
.m-player .btns #id-audio-player:hover {
background-position: -40px -204px;
}
.m-player .btns .state-pause {
background-position: 0px -204px !important;
}
.m-player .btns .state-pause:hover {
background-position: -40px -204px !important;
}
.m-player .btns .state-play {
background-position: 0px -165px !important;
}
.m-player .btns .state-play:hover {
background-position: -40px -165px !important;
}
#id-music-next {
background-position: -80px -130px;
}
#id-music-next:hover {
background-position: -110px -130px;
}
.btns a{
background: url('./images/playbar.png') no-repeat 0 9999px;
text-indent: -9999px;
display: block;
cursor: pointer;
width: 28px;
height: 28px;
float: left;
margin-top: 8.5px;
margin-right: 8px;
}
.m-pbar {
width: 493px;
/* line-height: 200px; */
/* vertical-align: center; */
/* margin: 0 auto; */
margin-top: 19px;
}
.play {
position: relative;
width: 493px;
float: left;
}
.barbg {
width: 493px;
height: 9px;
/* background 要放在 position 前面*/
background: url('./images/statbar.png') no-repeat 0 9999px;
background-position: right 0;
}
.cur {
position: absolute;
top: 0px;
left: 0px;
height: 9px;
background: url('./images/statbar.png') no-repeat 0 9999px;
background-position: left -66px;
margin-top: 19px;
}
.cur span {
background: url('./images/iconall.png') no-repeat;
background-position: 0 -250px;
width: 22px;
height: 24px;
display: inline-block;
position: absolute;
top: -7px;
right: -13px;
cursor: pointer;
}
.cur span i {
visibility: hidden;
display: inline-block;
width: 12px;
height: 12px;
background: url('./images/loading.gif');
position: absolute;
top: 5px;
right: 5px;
}
.music-time {
display: block;
float: left;
margin: 13px 0 0 25px;
color: white;
}
.volume {
display: block;
width: 80px;
float: right;
height: 47px;
}
.volume a {
display: block;
background: url("./images/playbar.png") no-repeat 0 9999px;
background-position: -2px -248px;
width: 25px;
height: 25px;
text-indent: -9999px;
margin-top: 11px;
}
.vol-bar {
background: url('./images/playbar.png') no-repeat 0 9999px;
background-position: 0 -503px;
width: 32px;
height: 113px;
/* transform: rotate(-90deg); */
position: relative;
top: -149px;
}
#vol-icon {
background: url('./images/iconall.png') no-repeat 0 9999px;
background-position: -40px -250px;
width: 18px;
height: 20px;
display: block;
position: relative;
left: -7px;
top: 95px;
cursor: pointer;
/* opacity: 1; */
}
.vbg {
position: relative;
width: 4px;
/* top: auto; */
bottom: -8px;
left: 14px;
height: 95px;
margin: 0px;
/* z-index: -100; */
/* opacity: 0; */
}
.vol-cur {
background: url('./images/playbar.png') no-repeat 0 9999px;
background-position: -40px bottom;
position: absolute;
width: 4px;
/* top: auto; */
bottom: 0px;
/* opacity: 1; */
}
</style> -->
<link rel="stylesheet" href="./index.css">
</head>
<body>
<div class="">
<div class="main">
<div class="main-lrc">
<section>
</section>
<section>
<div class="lrc"></div>
</section>
</div>
</div>
<div class="m-player">
<div class="btns">
<a id="id-music-pre" title=" 上一首"> </a>
<a id="id-audio-player" title="播放/暂停"></a>
<a id="id-music-next" title="下一首"></a>
</div>
<div class="play">
<div class="words"></div>
<div class="m-pbar">
<div class="rdy"></div>
<div class="m-pbar">
<div class="barbg">
<div class="rdy" style="width:0%;">
<!-- rdy -->
</div>
<div class="cur" style="width:0%">
<span class="z-load" id="auto-id">
<i></i>
</span>
</div>
</div>
<!-- <span class="music-time">时间</span> -->
</div>
</div>
</div>
<div class="music-time">
<span id="cur-time">00:00</span>
<span id="all-time">00:00</span>
</div>
<div class="volume">
<span>
<a href=""></a>
</span>
<div class="vol-bar">
<div class="vbg">
<div class="vol-cur"> </div>
<span id="vol-icon"></span>
</div>
</div>
</div>
<div class="">
</div>
</div>
<audio id="id-audio-content" data-state="0" >
<source src="./src/1.mp3">
</audio>
</div>
<script src="./tools.js"></script>
<!-- <script>
/*
1, 控制条
播放、暂停、切歌(图标要对上,暂停切歌时需要播放并切换图标)
播放进度
1, 播放条自动滑动
2, 鼠标拖拉控制进度
点下 获取当前值
移动 计算移动值 + 原进度, 并移动
松开 移除移动事件
3, 鼠标点击控制进取
音乐与进度条关联
1, 播放歌曲进度条自动滚动
2, 移动进度条播放能正常
第一个 bug (移动进度条放开后进度条弹回原处)
播放时间
当前时间
timeupdate 中格式绑定
总时间
bug 切歌的时 总时间会瞬间出现 NaN
(绑定在页面中代码放置位置有待确定)
音量控制
2, 歌词滚动
歌词显示
获取歌词
对歌词进行分解(时间、歌词各一个数组)
根据歌词在页面生成歌词列表
歌词绑定
点击播放 歌词能正确显示当前歌词(添加 class) 歌词开始 歌词结束能正确显示
暂停 歌词滚动能暂停
拖放歌词滚动条后放开回到原来的位置
切歌
3, 搜索歌曲 (爬虫)(ajax) 跨域
4,
*/
var musicSource = [
'1.mp3',
'2.mp3',
'3.mp3',
'4.mp3',
]
// var ad
var pre = document.querySelector('#id-music-pre')
var next = document.querySelector('#id-music-next')
var audio = document.querySelector('#id-audio-content')
var findMusicIndex = function(str) {
for (let i = 0; i < musicSource.length; i++) {
if(str == musicSource[i]) {
return i
}
}
return -1
}
// 播放音乐
var musicPlayer = function() {
var audio = document.querySelector('#id-audio-player')
var play = document.querySelector('#id-audio-content')
audio.addEventListener('click', function(e) {
var play = document.querySelector('#id-audio-content')
var stateValue = play.dataset.state
var state = Number(stateValue)
// console.log('state', state)
if(!state) {
// console.log('play')
play.play()
play.dataset.state = '1'
// audio.background.position = '0 -165px'
audio.classList.remove('state-pause')
audio.classList.add('state-play')
} else {
// console.log('pause')
play.pause()
play.dataset.state = '0'
audio.classList.remove('state-play')
audio.classList.add('state-pause')
// audio.background.position = '0 -204px'
}
})
}
// 前一首
pre.addEventListener('click', function(e) {
var src = document.querySelector('source')
var musicSrc = src.src
var musicName = musicSrc.split('/')[7]
// console.log(musicName)
var indexNow = findMusicIndex(musicName)
var index = (indexNow - 1 + 4) % 4
// console.log('index', indexNow, index, musicName)
var path = './src/' + musicSource[index]
src.src = path
// console.log(audio)
audio.load()
audio.play()
var play = document.querySelector('#id-audio-content')
play.dataset.state = '1'
var content = document.querySelector('#id-audio-player')
content.classList.add('state-play')
// console.log(path)
})
// 下一首
var nextEvent = function (){
next.addEventListener('click', function(e) {
var src = document.querySelector('source')
var musicSrc = src.src
var musicName = musicSrc.split('/')[7]
// console.log(musicName)
var indexNow = findMusicIndex(musicName)
var index = (indexNow + 1) % 4
// console.log('index', indexNow, index, musicName)
var path = './src/' + musicSource[index]
src.src = path
// console.log(audio)
audio.load()
audio.play()
// console.log(path)
// span_allTime(audio.duration)
var play = document.querySelector('#id-audio-content')
play.dataset.state = '1'
var content = document.querySelector('#id-audio-player')
content.classList.add('state-play')
// 总时间
// span_allTime(audio.duration)
})
}
// 播放结束自动切歌
audio.addEventListener('ended', function() {
var src = document.querySelector('source')
var musicSrc = src.src
var musicName = musicSrc.split('/')[7]
// console.log(musicName)
var indexNow = findMusicIndex(musicName)
var index = (indexNow + 1) % 4
// console.log('index', indexNow, index, musicName)
var path = './src/' + musicSource[index]
src.src = path
// console.log(audio)
audio.load()
audio.play()
var play = document.querySelector('#id-audio-content')
play.dataset.state = '1'
//总时间
// span_allTime(audio.duration)
}, false)
// 歌曲播放时进度条移动
audio.addEventListener('timeupdate', function() {
// console.log(audio.duration)
var preces = (audio.currentTime / audio.duration) * 100
// console.log('preces', preces)
//这里出错了 不用 .cur 宽度来改变进度条 应该用 currentTime 改变
if(!isDragging){
var div_cur = document.querySelector('.cur')
div_cur.style.width = `${preces}%`
}
// var div_cur = document.querySelector('.cur')
// div_cur.style.width = `${preces}%`
var fTime = formTime(audio.currentTime)
var time_span = document.querySelector('#cur-time')
time_span.innerHTML = fTime
// thisTime = audio.currentTime
// 切歌 bug 解决
var allTheTime = audio.duration || 0
span_allTime(allTheTime)
// 绑定歌词
// let timeCollect = tool.formatLrc()
// var timeCollects = timeCollect[1]
// for (let i = 0; i < timeCollect.length; i++) {
//
// }
tool.bindLyric()
})
// 点击 控制播放进度
var process_div = document.querySelector('.barbg')
var play_now = function() {
// var process_div = document.querySelector('.cur')
var process_cur = document.querySelector('.cur')
process_div.addEventListener('click', function(event) {
// var x = event.pageX || event.clientX + scrollX;
// console.log("process_div click", event.offsetX/493)
// offsetX 相对于父元素 x 距离 // TODO: WHY
// var press = (event.offsetX/493)*100
var boxLeft = this.getBoundingClientRect()
var press = ((event.clientX - boxLeft.left) / 493) * 100
// var press = event.offsetX
// console.log("process_div cur---click", press)
process_cur.style.width= `${press}%`
audio.currentTime = audio.duration * press * 0.01
})
}
var isDragging = false;
// var process_move = document.querySelector('#auto-id')
// var last_offX = 0
// process_move.addEventListener('mouseover', function() {
// var process_cur = document.querySelector('.cur')
// var now_offX = process_cur.style.width
// console.log('cur width', now_offX)
// console.log('拖动了',event.offsetX)
// var press = event.offsetX + last_offX
// // ((event.offsetX-last_offX)/493)*100
// last_offX = event.offsetX
// process_cur.style.width= `${press}px`
// })
// 鼠标滑动控制音量
var allTime = 0
var startPosition = 0
var curPostion = 0
var process_bar = document.querySelector('#barbg')
var process_move = document.querySelector('#auto-id')
var start = 0
var prassCur = document.querySelector('.cur')
// 移动进度条执行事物
var listen = function(e) {
console.log('this.')
if(!isDragging) return
// console.log('this.isDragging', this.isDragging
console.log('movemove')
var now = ((e.clientX - start) / 493)* 100
now = now + passC
now = Math.min(now, 100)
// console.log('e.clcient', typeof(e.clientX), typeof(passC), typeof(start))
prassCur.style.width =`${now}%`
curPostion = audio.duration * now * 0.01
// console.log('audio.cuurentime', curPostion)
// console.log('mousemove', e.clientX)
// console.log('now1', now, typeof(now))
// console.log('passC', passC)
// console.log('pass+now', now+passC)
}
// 开始移动进度条执行事物
var dragst = function(clientx, prassCur, start) {
var now = ((clientx - start) / 493)* 100
prassCur.style.width =`${now}%`
}
// 获取播放进度
var passCur = function() {
var prassCur = document.querySelector('.cur')
var startCur = prassCur.style.width
var startNow = startCur.slice(0, startCur.length - 1)
// startNow = startNow.parseFloat(startNow)
var startNum = (parseFloat(startNow) / 100) * 493
// console.log('startNow', typeof(startNow))
return parseFloat(startNow)
}
// 移动结束执行事物
var dragen = function() {
// console.log('mouseup',e.clientX)
// 获取当前 div 的宽度 算出百分比
// 把进度条跟播放时间绑定
var proc_now = document.querySelector('.cur')
var start_nows = proc_now.style.width
// var startNow = start_nows.slice(0, start_nows.length - 1)
// 更改播放时间
// console.log('audio.currentTime', audio.currentTime, typeof( audio.currentTime))
// console.log('start_nows', start_nows* 0.01 * audio.duration)
// console.log('dragend curPostion', curPostion)
// this.isDragging = false
// var prec11 = curPostion / audio.duration
// // console.log('prec11', prec11)
// var prec1 = prec11 * 100
// proc_now.style.width = `${prec1}%`
// thisTime = curPostion
audio.currentTime = curPostion
isDragging = false
// console.log('startNow, currentTime', startNow, audio.currentTime)
// console.log('currentTime', audio.currentTime)
// console.log('startNow', startNow)
// startNow = startNow.parseFloat(startNow)
// var startNum = (parseFloat(startNow) / 100) * 493
document.removeEventListener('mousemove', listen)
document.removeEventListener('mouseup', dragen)
console.log('mouseUp')
}
var passC = 0
// 拖动控制 播放进度
var dragEvent = function(){
process_move.addEventListener('mousedown', function(e) {
// var event = e.target
// console.log('mousedown', e.clientX)
// this.isDragging = false
// start = e.clientX
// var startPosition = passCur()
// allTime = audio.currentTime
// 阻止事件传播
e.stopPropagation()
isDragging = true
start = e.clientX
console.log('mousedown eclienx', e.clientX)
passC = passCur()
var prassCur = document.querySelector('.cur')
document.addEventListener('mousemove', listen)
document.addEventListener('mouseup', dragen)
})
}
//格式化时间
var formTime = function(time) {
var min = parseInt(time / 60)
var second
if(time > 60) {
second =parseInt((time % 60))
} else {
second = parseInt(time)
}
var formSecond
if(second < 10) {
formSecond = `0${second}`
} else {
formSecond = `${second}`
}
return `0${min}:${formSecond}`
}
var toSecond = function(time) {
let minStr = time.slice(0,2)
let secondStr = time.slice(3)
let min = parseInt(minStr)
let second = parseFloat(secondStr)
return min*60 + second
}
//总时间
var span_allTime = function(time) {
var span = document.querySelector('#all-time')
var allFormTime = formTime(time)
console.log('allTime', audio.duration)
span.innerHTML= allFormTime
}
var isVol = false
//音量控制
var vol_cur_proces = document.querySelector('.vol-cur')
var volControl = document.querySelector('.val-bar')
var vol_span = document.querySelector('#vol-icon')
var startNowY = 0
var vol_proces = 0
var vol_icon_now = 0
var top_all = 95
var process_all = 0
audio.volume = 0.5
var vol_i = 47.5
var vol_h = 47.5
vol_cur_proces.style.height = 47.5 + 'px'
vol_span.style.top = 47.5 - 10 + 'px'
var vol_drag = function(e) {
if(!isVol) return
console.log(isVol)
// console.log('drag move',startNowY - e.clientY)
var nowMove = startNowY - e.clientY
console.log(e.clientY)
// var movePx = top_all - nowMove + vol_i + 9
console.log('movePx nowMove', movePx, nowMove)
// top_all = movePx
var theP = vol_proces + nowMove
var movePx = vol_icon_now - nowMove
// var theP = process_all + nowMove
// var theI = vol_icon_now - nowMove
// console.log('vol_proces vol_now',vol_proces, vol_icon_now)
if(nowMove > 0){
movePx = Math.max(movePx, -10)
theP = Math.min(theP, 95)
} else {
movePx = Math.min(movePx, 95 - 10)
theP = Math.max(theP, 0)
}
// // console.log('------movePx------', movePx)
vol_cur_proces.style.height = `${theP}px`
vol_span.style.top = movePx + 'px'
vol_computer()
}
var vol_dragend = function() {
// vol_cur_proces.style.height = `${theP}px`
// vol_span.style.top = movePx + 'px'
isVol = false
// var vol_top = vol_span.style.top
// top_all = parseInt(vol_top.slice(0, -2)) | 0
// var vol_height = vol_cur_proces.style.height
// process_all = parseInt(vol_height.slice(0, -2)) | 0
// vol_i = 0
// var nowDiv = document.querySelector('.vol-cur')
// let nowDivHeight = nowDiv.style.height
// let nowDivStr = nowDivHeight.slice(0,-2)
// let vol_value = parseInt(nowDivStr)
// let vol_precent = vol_value / 95
// // console.log('vol_precent', vol_precent)
// audio.volume = vol_precent
vol_span.removeEventListener('mousemove', vol_drag)
vol_span.removeEventListener('mouseup', vol_dragend)
}
vol_span.addEventListener('mousedown', function(e) {
// body...
e.stopPropagation()
isVol = true
var startY = e.clientY
startNowY = startY
// console.log('vol mousedown', e.clientY)
var vol_height = vol_cur_proces.style.height
vol_proces = parseFloat(vol_height.slice(0, -2)) | 0
var vol_top = vol_span.style.top
vol_icon_now = parseFloat(vol_top.slice(0, -2)) | 0
console.log('vol proc now', vol_proces,vol_icon_now)
vol_span.addEventListener('mousemove',vol_drag)
vol_span.addEventListener('mouseup', vol_dragend)
})
function vol_computer() {
var nowDiv = document.querySelector('.vol-cur')
let nowDivHeight = nowDiv.style.height
let nowDivStr = nowDivHeight.slice(0,-2)
let vol_value = parseInt(nowDivStr)
let vol_precent = vol_value / 95
// console.log('vol_precent', vol_precent)
audio.volume = vol_precent
}
// 点击控制音量
// 可能需要事件捕获
var vol_click = document.querySelector('.vbg')
var volCurClick = document.querySelector('.vol-cur')
var contentBox = vol_click.getBoundingClientRect()
vol_click.addEventListener('click', function(e){
if(isVol) return
console.log('vol_click', e.clientY - parseFloat(vol_click.getBoundingClientRect().top) )
var iconHeight = e.clientY - contentBox.top
var paNow = 95 - iconHeight
vol_cur_proces.style.height = paNow + 'px'
vol_span.style.top = iconHeight - 10 + 'px'
vol_computer()
// console.log(e.target)
})
// volCurClick.addEventListener('click', function(e){
// console.log('volCurClick', e.offsetY)
// console.log(e.target)
// var paNow = 95 - e.offsetY
// var nowCurHeight = volCurClick.style.height
// var nowCurlen = nowCurHeight.slice(0, nowCurHeight.length - 2)
// console.log('现在' + nowCurlen)
// let paNowCur = e.offsetY - parseFloat(nowCurlen)
// vol_cur_proces.style.height = paNowCur + 'px'
// vol_span.style.top = e.offsetY - 9 + 'px'
// })
var tool = {
}
tool.lyric = function() {
// let lrc = '[00:16.445]如何面对曾一起走过的日子\
// [00:23.420]现在剩下我独行如何用心声一一讲你知\
// [00:30.116]从来没人明白我唯一你给我好日子\
// [00:37.315]有你有我有情有生有死有义\
// [00:43.395]多少风波都愿闯只因彼此不死的目光\
// [00:50.890]有你有我有情有天有海有地\
// [00:57.540]不可猜测总有天意才珍惜相处的日子\
// [01:04.650]道别话亦未多讲只抛低这个伤心的汉子\
// [01:18.843]沉沉睡了谁分享今生的日子\
// [01:25.775]活着但是没灵魂才明白生死之间的意思\
// [01:32.733]情浓完全明白了才甘心披上孤独衣\
// [01:39.663]有你有我有情有天有海有地\
// [01:46.637]当天一起不自知分开方知根本心极痴\
// [01:53.542]有你有我有情有生有死有义\
// [02:00.512]只想解释当我不智如今想倾诉讲谁知\
// [02:07.468]剩下绝望旧身影今只得千亿伤心的句子\
// [02:20.225]沉沉睡了谁分享今生的日子\
// [02:26.862]活着但是没灵魂才明白生死之间的意思\
// [02:33.821]情浓完全明白了才甘心披上孤独衣\
// [02:41.109]有你有我有情有天有海有地\
// [02:47.976]当天一起不自知分开方知根本心极痴\
// [02:54.946]有你有我有情有生有死有义\
// [03:01.961]只想解释当我不智如今想倾诉讲谁知\
// [03:08.561]剩下绝望旧身影今只得千亿伤心的句子\
// [03:14.566]剩下绝望旧身影今只得千亿伤心的句子\
// '
let lrc = "[00:00.00] 作曲 : Macy gray\
[00:01.00] 作词 : Macy gray\
[00:04.83]Uh It's remix baby\
[00:09.15]You gonna love it\
[00:11.49]Ready Uh Yeah Come on\
[00:18.16]记得你说你总是对的,那些琐碎你觉得累了\
[00:22.46]谁该道歉谁对谁错,那些疑惑我无所谓的\
[00:27.04]Baby you are my memory\
[00:29.31]我说时间它或许可以\
[00:31.44]能够让你把我遗忘的彻底\
[00:33.70]So please don't say I'm creepy\
[00:36.04]你想要的这不是我能给,不想再让你变的更憔悴\
[00:40.44]我说其实回忆也可以很美\
[00:42.74]Everything will be OK\
[00:44.89]我给你一个可以放手的借口,只是需要时间去接受\
[00:49.35]所以现在我让你先走\
[00:51.84]Now, I let you go, I let you go\
[00:55.14]And if I had to do it over, I'd see you again (see you again)\
[01:00.01]I'd do it right and when we fight I'd let you win (I let you win)\
[01:04.03]'Cause my world is nearly nothing without you in it (uh)\
[01:09.02]Should-a let it go\
[01:10.32]Could-a let you go (let you go)\
[01:11.38]Could-a let you win\
[01:14.22]Ready Uh\
[01:16.49]离开的理由我只需要一个\
[01:18.91]I just wanna make you feel better\
[01:21.02]无论以后会有多少个不舍,但是为你 It does't matter\
[01:25.32]我说生活能有很多个焦点\
[01:27.70]You gonna do it,这是唯一条件\
[01:29.91]过去你不必再留恋,你需要的是一个全新起点\
[01:34.29]我想我了解你所有的秘密,那些记忆都存在了日记\
[01:38.78]Congratulations 你现在终于\
[01:41.01]能够找回到全新的自己\
[01:43.18]我说过去我从不会否定,我只想现在让自己安静\
[01:47.79]试着离开你紧握的手心\
[01:50.04]So I let you win, I let you win\
[01:53.47]And if I had to do it over, I'd see you again (see you again)\
[01:58.41]I'd do it right and when we fight I'd let you win (I let you win)\
[02:02.79]'Cause my world is nearly nothing without you in it\
[02:07.32]Should-a let it go\
[02:08.48]Could-a let it go\
[02:09.74]Could-a let you win\
[02:12.54]I let you go, I let you win\
[02:17.02]I let you go, I let you win, Baby\
[02:21.48]I let you go, I let you win\
[02:25.95]I let you go, I let you win, Baby\
[02:31.56]And if I had to do it over, I'd see you again\
[02:36.50]I'd do it right and when we fight I'd let you win (I let you win)\
[02:40.84]'Cause my world is nearly nothing without you in it\
[02:45.57]Should-a let it go (let it go)\
[02:46.76]Could-a let it go (let it go)\
[02:47.99]Could-a let you win (let you win)\
[02:49.53]Let you win (let you win), let you win (let you win)\
[02:53.90]Let you win, let you win (let you win), let you win\
[02:58.51]Let you win (I let you win, let you win)\
[03:00.83]I give in (I give in)\
[03:02.88]Let you win\
[03:04.04]Wanna see you again (wanna see you again)\
[03:08.35]Uh remix, Uh Yeah"
return lrc
}
// 时间 歌词分割
tool.formatLrc = function() {
let lyricTimes = []
let lyrics = []
let temp = []
let lyric = null
let copyLyric = null
let timeRegex = /\[\d+:\d+\.\d+\]/g
let lyricRegex = /[^\[\d+:\d+\.\d+\]]/g
let regex = /\[/g
copyLyric = lyric = tool.lyric()
// 把时间都替换成 '_', 再用 split 把字符串分割成字符串数组
copyLyric = copyLyric.replace(timeRegex, '_').split('_')
// split() 把字符串分割成字符数组
lyric = lyric.replace(lyricRegex, '').replace(regex, '').split(']');
copyLyric.forEach(function(item) {
if(item) {
lyrics.push(item.trim())
}
})
lyric.forEach((item)=> {
if(item) {
lyricTimes.push(item.trim())
}
})
// console.log('lyrics + lyricTimes', lyrics,lyricTimes)
return [lyricTimes, lyrics]
}
// 歌词显示在界面
var divLyric = document.querySelector('.lrc')
tool.showlyric = function(ele, lyrics) {
var parentNode = []
var eleNode = create('p', lyrics.length)
for (let i = 0; i < lyrics.length; i++) {
eleNode[i].innerHTML = lyrics[i]
// appendHtml(divLyric, `<p>${lyrics[i]}</p>`)
// parentNode.push(`<p>${lyrics[i]}</p>`)
}
for (let i = 0; i < eleNode.length; i++) {
// body...
// divLyric.appendHtml('beforeend', eleNode[i])
divLyric.appendChild(eleNode[i])
}
return eleNode
}
// 绑定歌词 timeupdate 中
var removeClass = function(element, className) {
if(!element || !className) {
return
}
element.classList.remove(className)
}
var addClass = function(element, className) {
if(!element) {
return
}
element.className = className
}
var create = function(eleType,length) {
if(!eleType || !length) {
return
}
var eleNode = []
for (let i = 0; i < length; i++) {
eleNode.push(document.createElement(eleType))
}
return eleNode
}
var currentLine = null
let Collect = tool.formatLrc()
var timeCollect = Collect[0]
var lyricCollect = Collect[1]
var theLyric = tool.showlyric(divLyric, lyricCollect)
// console.log('theLyric', theLyric)
tool.bindLyric = function() {
let Collect = tool.formatLrc()
var timeCollect = Collect[0]
var lyricCollect = Collect[1]
let lyricScrollHeight = divLyric.scrollHeight
for (let i = 0; i < timeCollect.length; i++) {
if(toSecond(timeCollect[i]) - audio.currentTime <= 0.01) {
removeClass(currentLine, 'on')
// console.log(' removeClass',toSecond(timeCollect[i]))
// 这里卡住了
// 首先获取节点,然后给节点加 on 类
currentLine = theLyric[i]
//移动滚动条
divLyric.scrollTop = currentLine.offsetTop - currentLine.offsetHeight * 7
// 获取 p 元素再添加类
// console.log('currentLine', currentLine, typeof(currentLine))
addClass(currentLine, 'on')
}
}
if(timeCollect.length === 0) {
removeClass(currentLine, on)
}
}
// process_move.addEventListener('onmousedown', function(e) {
// console.log('can move')
// // process_move.style.draggable = true
// })
// process_move.addEventListener('onmousemove', function(e) {
// console.log('move')
// })
// process_move.addEventListener('onmousedup', function(e) {
// console.log('up')
// })
// 程序入口
var __main = function() {
musicPlayer()
nextEvent()
play_now()
dragEvent()
tool.formatLrc()
var uijm = ''
var geci = ''
[uijm, geci] = tool.formatLrc()
}
__main()
</script> -->
<script src="./audioNow.js" charset="utf-8"></script>
</body>
</html>