File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,13 +113,13 @@ class APlayer {
113113
114114 this . on ( 'play' , ( ) => {
115115 if ( this . paused ) {
116- this . play ( ) ;
116+ this . setUIPlaying ( ) ;
117117 }
118118 } ) ;
119119
120120 this . on ( 'pause' , ( ) => {
121121 if ( ! this . paused ) {
122- this . pause ( ) ;
122+ this . setUIPaused ( ) ;
123123 }
124124 } ) ;
125125
@@ -302,7 +302,7 @@ class APlayer {
302302 this . template . ptime . innerHTML = utils . secondToTime ( time ) ;
303303 }
304304
305- play ( ) {
305+ setUIPlaying ( ) {
306306 if ( this . paused ) {
307307 this . paused = false ;
308308 this . template . button . classList . remove ( 'aplayer-play' ) ;
@@ -313,15 +313,6 @@ class APlayer {
313313 } , 100 ) ;
314314 }
315315
316- const playPromise = this . audio . play ( ) ;
317- if ( playPromise ) {
318- playPromise . catch ( ( e ) => {
319- if ( e . name === 'NotAllowedError' ) {
320- this . pause ( ) ;
321- }
322- } ) ;
323- }
324-
325316 this . timer . enable ( 'loading' ) ;
326317
327318 if ( this . options . mutex ) {
@@ -333,7 +324,22 @@ class APlayer {
333324 }
334325 }
335326
336- pause ( ) {
327+ play ( ) {
328+ this . setUIPlaying ( ) ;
329+
330+ const playPromise = this . audio . play ( ) ;
331+ if ( playPromise ) {
332+ playPromise . catch ( ( e ) => {
333+ console . error ( e ) ;
334+ if ( e . name === 'NotAllowedError' ||
335+ e . name === 'NotSupportedError' ) {
336+ this . setUIPaused ( ) ;
337+ }
338+ } ) ;
339+ }
340+ }
341+
342+ setUIPaused ( ) {
337343 if ( ! this . paused ) {
338344 this . paused = true ;
339345
@@ -345,12 +351,15 @@ class APlayer {
345351 } , 100 ) ;
346352 }
347353
348- this . audio . pause ( ) ;
349-
350354 this . container . classList . remove ( 'aplayer-loading' ) ;
351355 this . timer . disable ( 'loading' ) ;
352356 }
353357
358+ pause ( ) {
359+ this . setUIPaused ( ) ;
360+ this . audio . pause ( ) ;
361+ }
362+
354363 switchVolumeIcon ( ) {
355364 if ( this . volume ( ) >= 0.95 ) {
356365 this . template . volumeButton . innerHTML = Icons . volumeUp ;
You can’t perform that action at this time.
0 commit comments