|
|
@ -1,9 +1,10 @@
|
|
|
|
import { updateMediaSessionMetaData } from "@/utils/mediaSession";
|
|
|
|
import { updateMediaSessionMetaData } from "@/utils/mediaSession";
|
|
|
|
import { getTrackDetail, scrobble } from "@/api/track";
|
|
|
|
import { getTrackDetail, scrobble, getMP3 } from "@/api/track";
|
|
|
|
|
|
|
|
import { isLoggedIn } from "@/utils/auth";
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
switchTrack({ state, dispatch, commit }, basicTrack) {
|
|
|
|
switchTrack({ state, dispatch, commit }, basicTrack) {
|
|
|
|
getTrackDetail(basicTrack.id).then((data) => {
|
|
|
|
getTrackDetail(basicTrack.id).then(data => {
|
|
|
|
let track = data.songs[0];
|
|
|
|
let track = data.songs[0];
|
|
|
|
track.sort = basicTrack.sort;
|
|
|
|
track.sort = basicTrack.sort;
|
|
|
|
|
|
|
|
|
|
|
@ -11,9 +12,7 @@ export default {
|
|
|
|
scrobble({
|
|
|
|
scrobble({
|
|
|
|
id: state.player.currentTrack.id,
|
|
|
|
id: state.player.currentTrack.id,
|
|
|
|
sourceid: state.player.listInfo.id,
|
|
|
|
sourceid: state.player.listInfo.id,
|
|
|
|
time: time === 0 ? 180 : time,
|
|
|
|
time: time === 0 ? 180 : time
|
|
|
|
}).then((data) => {
|
|
|
|
|
|
|
|
console.log("scrobble", data);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
commit("updateCurrentTrack", track);
|
|
|
|
commit("updateCurrentTrack", track);
|
|
|
@ -25,36 +24,43 @@ export default {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
commit(
|
|
|
|
function commitMP3(mp3) {
|
|
|
|
"replaceMP3",
|
|
|
|
commit("replaceMP3", mp3);
|
|
|
|
`https://music.163.com/song/media/outer/url?id=${track.id}`
|
|
|
|
state.howler.once("end", () => {
|
|
|
|
);
|
|
|
|
dispatch("nextTrack");
|
|
|
|
state.howler.once("end", () => {
|
|
|
|
});
|
|
|
|
dispatch("nextTrack");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (isLoggedIn) {
|
|
|
|
|
|
|
|
getMP3(track.id).then(data => {
|
|
|
|
|
|
|
|
commitMP3(data.data[0].url);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
commitMP3(`https://music.163.com/song/media/outer/url?id=${track.id}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
playFirstTrackOnList({ state, dispatch }) {
|
|
|
|
playFirstTrackOnList({ state, dispatch }) {
|
|
|
|
dispatch(
|
|
|
|
dispatch(
|
|
|
|
"switchTrack",
|
|
|
|
"switchTrack",
|
|
|
|
state.player.list.find((t) => t.sort === 0)
|
|
|
|
state.player.list.find(t => t.sort === 0)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
playTrackOnListByID({ state, commit, dispatch }, trackID) {
|
|
|
|
playTrackOnListByID({ state, commit, dispatch }, trackID) {
|
|
|
|
let track = state.player.list.find((t) => t.id === trackID);
|
|
|
|
let track = state.player.list.find(t => t.id === trackID);
|
|
|
|
dispatch("switchTrack", track);
|
|
|
|
dispatch("switchTrack", track);
|
|
|
|
if (state.player.shuffle) {
|
|
|
|
if (state.player.shuffle) {
|
|
|
|
// 当随机模式开启时,双击列表的一首歌进行播放,此时要把这首歌的sort调到第一(0),这样用户就能随机播放完整的歌单
|
|
|
|
// 当随机模式开启时,双击列表的一首歌进行播放,此时要把这首歌的sort调到第一(0),这样用户就能随机播放完整的歌单
|
|
|
|
let otherTrack = state.player.list.find((t) => t.sort === 0);
|
|
|
|
let otherTrack = state.player.list.find(t => t.sort === 0);
|
|
|
|
commit("switchSortBetweenTwoTracks", {
|
|
|
|
commit("switchSortBetweenTwoTracks", {
|
|
|
|
trackID1: track.id,
|
|
|
|
trackID1: track.id,
|
|
|
|
trackID2: otherTrack.id,
|
|
|
|
trackID2: otherTrack.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nextTrack({ state, dispatch }, realNext = false) {
|
|
|
|
nextTrack({ state, dispatch }, realNext = false) {
|
|
|
|
let nextTrack = state.player.list.find(
|
|
|
|
let nextTrack = state.player.list.find(
|
|
|
|
(track) => track.sort === state.player.currentTrack.sort + 1
|
|
|
|
track => track.sort === state.player.currentTrack.sort + 1
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (state.player.repeat === "one" && realNext === false) {
|
|
|
|
if (state.player.repeat === "one" && realNext === false) {
|
|
|
@ -63,7 +69,7 @@ export default {
|
|
|
|
|
|
|
|
|
|
|
|
if (nextTrack === undefined) {
|
|
|
|
if (nextTrack === undefined) {
|
|
|
|
if (state.player.repeat !== "off") {
|
|
|
|
if (state.player.repeat !== "off") {
|
|
|
|
nextTrack = state.player.list.find((t) => t.sort === 0);
|
|
|
|
nextTrack = state.player.list.find(t => t.sort === 0);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,13 +79,13 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
previousTrack({ state, dispatch }) {
|
|
|
|
previousTrack({ state, dispatch }) {
|
|
|
|
let previousTrack = state.player.list.find(
|
|
|
|
let previousTrack = state.player.list.find(
|
|
|
|
(track) => track.sort === state.player.currentTrack.sort - 1
|
|
|
|
track => track.sort === state.player.currentTrack.sort - 1
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (previousTrack == undefined) {
|
|
|
|
if (previousTrack == undefined) {
|
|
|
|
if (state.player.repeat !== "off") {
|
|
|
|
if (state.player.repeat !== "off") {
|
|
|
|
previousTrack = state.player.list.reduce((x, y) => (x > y ? x : y));
|
|
|
|
previousTrack = state.player.list.reduce((x, y) => (x > y ? x : y));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
previousTrack = state.player.list.find((t) => t.sort === 0);
|
|
|
|
previousTrack = state.player.list.find(t => t.sort === 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dispatch("switchTrack", previousTrack);
|
|
|
|
dispatch("switchTrack", previousTrack);
|
|
|
@ -88,5 +94,5 @@ export default {
|
|
|
|
state.howler.once("end", () => {
|
|
|
|
state.howler.once("end", () => {
|
|
|
|
dispatch("nextTrack");
|
|
|
|
dispatch("nextTrack");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|