File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,16 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
8686 }
8787 }
8888
89+ & .aplayer-loading {
90+ .aplayer-info .aplayer-controller .aplayer-loading-icon {
91+ display : block ;
92+ }
93+
94+ .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-played .aplayer-thumb {
95+ transform : scale (1 );
96+ }
97+ }
98+
8999 .aplayer-icon {
90100 width : 15px ;
91101 height : 15px ;
@@ -345,6 +355,15 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
345355 }
346356 }
347357 }
358+
359+ .aplayer-loading-icon {
360+ display : none ;
361+
362+ svg {
363+ position : absolute ;
364+ animation : rotate 1s linear infinite ;
365+ }
366+ }
348367 }
349368 }
350369
@@ -496,3 +515,12 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
496515 0% {left :0 }
497516 100% {left : -100% }
498517}
518+
519+ @keyframes rotate {
520+ 0% {
521+ transform : rotate (0 )
522+ }
523+ 100% {
524+ transform : rotate (360deg )
525+ }
526+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import menu from '../assets/menu.svg';
99import loopAll from '../assets/loop-all.svg' ;
1010import loopOne from '../assets/loop-one.svg' ;
1111import loopNone from '../assets/loop-none.svg' ;
12+ import loading from '../assets/loading.svg' ;
1213
1314const Icons = {
1415 play : play ,
@@ -22,6 +23,7 @@ const Icons = {
2223 loopAll : loopAll ,
2324 loopOne : loopOne ,
2425 loopNone : loopNone ,
26+ loading : loading ,
2527} ;
2628
2729export default Icons ;
Original file line number Diff line number Diff line change @@ -250,6 +250,7 @@ class APlayer {
250250 this . pause ( ) ;
251251 } ) ;
252252
253+ this . timer . enable ( 'loading' ) ;
253254 this . timer . enable ( 'progress' ) ;
254255
255256 if ( this . options . mutex ) {
@@ -282,6 +283,7 @@ class APlayer {
282283
283284 this . audio . pause ( ) ;
284285
286+ this . timer . disable ( 'loading' ) ;
285287 this . timer . disable ( 'progress' ) ;
286288 } ) ;
287289 }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class Timer {
1515 }
1616 ) ( ) ;
1717
18- this . types = [ 'progress' ] ;
18+ this . types = [ 'loading' , ' progress'] ;
1919
2020 this . init ( ) ;
2121 }
@@ -42,6 +42,31 @@ class Timer {
4242 } , 100 ) ;
4343 }
4444
45+ initloadingChecker ( ) {
46+ let lastPlayPos = 0 ;
47+ let currentPlayPos = 0 ;
48+ let bufferingDetected = false ;
49+ this . loadingChecker = setInterval ( ( ) => {
50+ if ( this . enableloadingChecker ) {
51+ // whether the audio is buffering
52+ currentPlayPos = this . player . audio . currentTime ;
53+ if ( ! bufferingDetected
54+ && currentPlayPos === lastPlayPos
55+ && ! this . player . audio . paused ) {
56+ this . player . container . classList . add ( 'aplayer-loading' ) ;
57+ bufferingDetected = true ;
58+ }
59+ if ( bufferingDetected
60+ && currentPlayPos > lastPlayPos
61+ && ! this . player . audio . paused ) {
62+ this . player . container . classList . remove ( 'aplayer-loading' ) ;
63+ bufferingDetected = false ;
64+ }
65+ lastPlayPos = currentPlayPos ;
66+ }
67+ } , 100 ) ;
68+ }
69+
4570 enable ( type ) {
4671 this [ `enable${ type } Checker` ] = true ;
4772
Original file line number Diff line number Diff line change 1414 <div class="aplayer-bar">
1515 <div class="aplayer-loaded" style="width: 0"></div>
1616 <div class="aplayer-played" style="width: 0; background: {{ options.theme }};">
17- <span class="aplayer-thumb" style="background: {{ options.theme }};"></span>
17+ <span class="aplayer-thumb" style="background: {{ options.theme }};">
18+ <span class="aplayer-loading-icon">{{@ icons.loading }}</span>
19+ </span>
1820 </div>
1921 </div>
2022 </div>
You can’t perform that action at this time.
0 commit comments