Skip to content

Commit c0e8684

Browse files
committed
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.
1 parent ea7a97a commit c0e8684

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/APlayer.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ class APlayer {
434434
this.setMusic(0);
435435
}
436436

437+
// autoplay
438+
if (this.option.autoplay && !this.isMobile) {
439+
this.play();
440+
}
441+
437442
instances.push(this);
438443
}
439444

@@ -717,12 +722,6 @@ class APlayer {
717722
if (this.audio.duration !== 1) { // compatibility: Android browsers will output 1 at first
718723
this.element.getElementsByClassName('aplayer-dtime')[0].innerHTML = this.audio.duration ? this.secondToTime(this.audio.duration) : '00:00';
719724
}
720-
721-
// autoplay
722-
if (this.option.autoplay && !this.isMobile) {
723-
this.play();
724-
}
725-
this.option.autoplay = true; // autoplay next music
726725
}
727726

728727
/**

0 commit comments

Comments
 (0)