From c0e868484a64bbb87d57f4c760aa5e71b1919b88 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Tue, 12 Dec 2017 13:09:35 -0500 Subject: [PATCH] Move the autoplay check into the constructor The `autoplay` option only makes sense in the constructor. After that, callers of `setMusic` should determine whether or not to begin playback based on their own state. --- src/APlayer.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/APlayer.js b/src/APlayer.js index 7ae23fc..68050d2 100644 --- a/src/APlayer.js +++ b/src/APlayer.js @@ -434,6 +434,11 @@ class APlayer { this.setMusic(0); } + // autoplay + if (this.option.autoplay && !this.isMobile) { + this.play(); + } + instances.push(this); } @@ -717,12 +722,6 @@ class APlayer { if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first this.element.getElementsByClassName('aplayer-dtime')[0].innerHTML = this.audio.duration ? this.secondToTime(this.audio.duration) : '00:00'; } - - // autoplay - if (this.option.autoplay && !this.isMobile) { - this.play(); - } - this.option.autoplay = true; // autoplay next music } /**