File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,11 +62,11 @@ class Controller {
6262 percentage = Math . min ( percentage , 1 ) ;
6363 this . player . bar . set ( 'played' , percentage , 'width' ) ;
6464 this . player . seek ( this . player . bar . get ( 'played' , 'width' ) * this . player . audio . duration ) ;
65- this . player . timer . enable ( 'progress' ) ;
65+ this . player . disableTimeupdate = true ;
6666 } ;
6767
6868 this . player . template . barWrap . addEventListener ( utils . nameMap . dragStart , ( ) => {
69- this . player . timer . disable ( 'progress' ) ;
69+ this . player . disableTimeupdate = false ;
7070 document . addEventListener ( utils . nameMap . dragMove , thumbMove ) ;
7171 document . addEventListener ( utils . nameMap . dragEnd , thumbUp ) ;
7272 } ) ;
Original file line number Diff line number Diff line change @@ -121,6 +121,17 @@ class APlayer {
121121 }
122122 } ) ;
123123
124+ this . on ( 'timeupdate' , ( ) => {
125+ if ( ! this . disableTimeupdate ) {
126+ this . bar . set ( 'played' , this . audio . currentTime / this . audio . duration , 'width' ) ;
127+ this . lrc && this . lrc . update ( ) ;
128+ const currentTime = utils . secondToTime ( this . audio . currentTime ) ;
129+ if ( this . template . ptime . innerHTML !== currentTime ) {
130+ this . template . ptime . innerHTML = currentTime ;
131+ }
132+ }
133+ } ) ;
134+
124135 // show audio time: the metadata has loaded or changed
125136 this . on ( 'durationchange' , ( ) => {
126137 if ( this . audio . duration !== 1 ) { // compatibility: Android browsers will output 1 at first
@@ -268,7 +279,6 @@ class APlayer {
268279 } ) ;
269280
270281 this . timer . enable ( 'loading' ) ;
271- this . timer . enable ( 'progress' ) ;
272282
273283 if ( this . options . mutex ) {
274284 for ( let i = 0 ; i < instances . length ; i ++ ) {
@@ -298,7 +308,6 @@ class APlayer {
298308 this . audio . pause ( ) ;
299309
300310 this . timer . disable ( 'loading' ) ;
301- this . timer . disable ( 'progress' ) ;
302311 } ) ;
303312 }
304313
Original file line number Diff line number Diff line change 1- import utils from './utils' ;
21
32class Timer {
43 constructor ( player ) {
@@ -15,7 +14,7 @@ class Timer {
1514 }
1615 ) ( ) ;
1716
18- this . types = [ 'loading' , 'progress' ] ;
17+ this . types = [ 'loading' ] ;
1918
2019 this . init ( ) ;
2120 }
@@ -27,19 +26,6 @@ class Timer {
2726 } ) ;
2827 }
2928
30- initprogressChecker ( ) {
31- this . progressChecker = setInterval ( ( ) => {
32- if ( this . enableprogressChecker ) {
33- this . player . bar . set ( 'played' , this . player . audio . currentTime / this . player . audio . duration , 'width' ) ;
34- this . player . lrc && this . player . lrc . update ( ) ;
35- const currentTime = utils . secondToTime ( this . player . audio . currentTime ) ;
36- if ( this . player . template . ptime . innerHTML !== currentTime ) {
37- this . player . template . ptime . innerHTML = currentTime ;
38- }
39- }
40- } , 100 ) ;
41- }
42-
4329 initloadingChecker ( ) {
4430 let lastPlayPos = 0 ;
4531 let currentPlayPos = 0 ;
You can’t perform that action at this time.
0 commit comments