@@ -125,7 +125,7 @@ class APlayer {
125125
126126 this . on ( 'timeupdate' , ( ) => {
127127 if ( ! this . disableTimeupdate ) {
128- this . bar . set ( 'played' , this . audio . currentTime / this . audio . duration , 'width' ) ;
128+ this . bar . set ( 'played' , this . audio . currentTime / this . duration , 'width' ) ;
129129 this . lrc && this . lrc . update ( ) ;
130130 const currentTime = utils . secondToTime ( this . audio . currentTime ) ;
131131 if ( this . template . ptime . innerHTML !== currentTime ) {
@@ -136,20 +136,22 @@ class APlayer {
136136
137137 // show audio time: the metadata has loaded or changed
138138 this . on ( 'durationchange' , ( ) => {
139- if ( this . audio . duration !== 1 ) { // compatibility: Android browsers will output 1 at first
140- this . template . dtime . innerHTML = utils . secondToTime ( this . audio . duration ) ;
139+ if ( this . duration !== 1 ) { // compatibility: Android browsers will output 1 at first
140+ this . template . dtime . innerHTML = utils . secondToTime ( this . duration ) ;
141141 }
142142 } ) ;
143143
144144 // show audio loaded bar: to inform interested parties of progress downloading the media
145145 this . on ( 'progress' , ( ) => {
146- const percentage = this . audio . buffered . length ? this . audio . buffered . end ( this . audio . buffered . length - 1 ) / this . audio . duration : 0 ;
146+ const percentage = this . audio . buffered . length ? this . audio . buffered . end ( this . audio . buffered . length - 1 ) / this . duration : 0 ;
147147 this . bar . set ( 'loaded' , percentage , 'width' ) ;
148148 } ) ;
149149
150150 // audio download error: an error occurs
151151 this . on ( 'error' , ( ) => {
152- this . notice ( 'An audio error has occurred.' ) ;
152+ if ( this . list . audios . length ) {
153+ this . notice ( 'An audio error has occurred.' ) ;
154+ }
153155 } ) ;
154156
155157 // multiple audio play
@@ -242,8 +244,8 @@ class APlayer {
242244 }
243245
244246 theme ( color = this . list . audios [ this . list . index ] . theme || this . options . theme , index = this . list . index ) {
245- this . list . audios [ index ] . theme = color ;
246- this . template . listCurs [ index ] . style . backgroundColor = color ;
247+ this . list . audios [ index ] && ( this . list . audios [ index ] . theme = color ) ;
248+ this . template . listCurs [ index ] && ( this . template . listCurs [ index ] . style . backgroundColor = color ) ;
247249 if ( index === this . list . index ) {
248250 this . template . pic . style . backgroundColor = color ;
249251 this . template . played . style . background = color ;
@@ -254,21 +256,16 @@ class APlayer {
254256
255257 seek ( time ) {
256258 time = Math . max ( time , 0 ) ;
257- if ( this . audio . duration ) {
258- time = Math . min ( time , this . audio . duration ) ;
259- }
260-
259+ time = Math . min ( time , this . duration ) ;
261260 this . audio . currentTime = time ;
262-
263- if ( isNaN ( this . audio . duration ) ) {
264- this . bar . set ( 'played' , 0 , 'width' ) ;
265- }
266- else {
267- this . bar . set ( 'played' , time / this . audio . duration , 'width' ) ;
268- }
261+ this . bar . set ( 'played' , time / this . duration , 'width' ) ;
269262 this . template . ptime . innerHTML = utils . secondToTime ( time ) ;
270263 }
271264
265+ get duration ( ) {
266+ return isNaN ( this . audio . duration ) ? 0 : this . audio . duration ;
267+ }
268+
272269 setUIPlaying ( ) {
273270 if ( this . paused ) {
274271 this . paused = false ;
0 commit comments