refactor: Adjusting music initialization logic

1.  Initial music loads twice on app start, a second load is triggered as soon as the page is clicked. So I close autounlock
2. Unplayable music can’t be play
This commit is contained in:
njzy 2020-12-05 20:42:50 +08:00
parent ddebec9de9
commit 200c49e8c9
5 changed files with 33 additions and 42 deletions

View file

@ -144,7 +144,7 @@ export default {
mounted() {
setInterval(() => {
// fix _id
if (this.howler && this.howler._sounds[0]._id) {
if (this.howler && this.howler._sounds?.[0]?._id) {
this.progress = ~~this.howler.seek();
}
}, 1000);
@ -169,13 +169,17 @@ export default {
},
},
playing() {
if (this.howler.state() === "loading") {
this.updatePlayerState({ key: "playing", value: true });
return true;
if (this.howler) {
if (this.howler.state() === "loading") {
this.updatePlayerState({ key: "playing", value: true });
return true;
}
const status = this.howler.playing();
this.updatePlayerState({ key: "playing", value: status });
return status;
} else {
return false;
}
const status = this.howler.playing();
this.updatePlayerState({ key: "playing", value: status });
return status;
},
progressMax() {
let max = ~~(this.currentTrack.dt / 1000);