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:
+5
-6
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user