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.
This commit is contained in:
Eric Robinson
2017-12-12 13:09:35 -05:00
parent ea7a97af3f
commit c0e868484a
+5 -6
View File
@@ -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
}
/**