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

@ -4,7 +4,7 @@ import state from "./state";
import mutations from "./mutations";
import actions from "./actions";
import initLocalStorage from "./initLocalStorage";
import { Howl, Howler } from "howler";
import { Howler } from "howler";
import { changeAppearance } from "@/utils/common";
import updateApp from "@/utils/updateApp";
import pkg from "../../package.json";
@ -39,15 +39,17 @@ const options = {
const store = new Vuex.Store(options);
store.state.howler = new Howl({
src: [
`https://music.163.com/song/media/outer/url?id=${store.state.player.currentTrack.id}`,
],
html5: true,
format: ["webm", "mp3"],
});
Howler.volume(store.state.player.volume);
// 防止软件第一次打开资源加载2次
Howler.autoUnlock = false;
const currentTrackId = store.state?.player?.currentTrack?.id;
if (currentTrackId) {
store.dispatch("switchTrack", {
id: currentTrackId,
autoplay: false,
});
}
if ([undefined, null].includes(store.state.settings.lang)) {
let lang = "en";