增加收藏歌曲和收藏歌单功能,优化播放器逻辑,修复bug以及体验优化

master
qier222 4 years ago
parent 5f0ef06786
commit 7f75758b73

@ -11,7 +11,11 @@
<Player <Player
v-if="this.$store.state.player.enable" v-if="this.$store.state.player.enable"
ref="player" ref="player"
v-show="this.$route.name !== 'mv'" v-show="
['mv', 'loginUsername', 'login', 'loginAccount'].includes(
this.$route.name
) === false
"
/></transition> /></transition>
<GlobalEvents :filter="globalEventFilter" @keydown.space="play" /> <GlobalEvents :filter="globalEventFilter" @keydown.space="play" />
</div> </div>
@ -50,13 +54,9 @@ export default {
font-family: "Barlow", -apple-system, BlinkMacSystemFont, Helvetica Neue, font-family: "Barlow", -apple-system, BlinkMacSystemFont, Helvetica Neue,
PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC,
WenQuanYi Micro Hei, sans-serif; WenQuanYi Micro Hei, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
// margin-top: 60px;
width: 100%; width: 100%;
} }
html { html {
overflow-y: overlay; overflow-y: overlay;
min-width: 1000px; min-width: 1000px;
@ -78,7 +78,6 @@ button {
} }
input, input,
button { button {
font-family: "Barlow", sans-serif;
&:focus { &:focus {
outline: none; outline: none;
} }

@ -1,4 +1,5 @@
import request from "@/utils/request"; import request from "@/utils/request";
import { mapTrackPlayableStatus } from "@/utils/common";
export function getAlbum(id) { export function getAlbum(id) {
return request({ return request({
@ -7,6 +8,9 @@ export function getAlbum(id) {
params: { params: {
id, id,
}, },
}).then((data) => {
data.songs = mapTrackPlayableStatus(data.songs);
return data;
}); });
} }

@ -9,6 +9,7 @@ export function getArtist(id) {
}, },
}); });
} }
export function getArtistAlbum(params) { export function getArtistAlbum(params) {
// 必选参数 : id: 歌手 id // 必选参数 : id: 歌手 id
// 可选参数 : limit: 取出数量 , 默认为 50 // 可选参数 : limit: 取出数量 , 默认为 50

@ -1,9 +1,14 @@
import request from "@/utils/request"; import request from "@/utils/request";
import { mapTrackPlayableStatus } from "@/utils/common";
export function search(params) { export function search(params) {
return request({ return request({
url: "/search", url: "/search",
method: "get", method: "get",
params, params,
}).then((data) => {
if (data.result.song !== undefined)
data.result.song.songs = mapTrackPlayableStatus(data.result.song.songs);
return data;
}); });
} }

@ -17,13 +17,13 @@ export function dailyRecommendPlaylist(params) {
}); });
} }
export function getPlaylistDetail(id) { export function getPlaylistDetail(id, noCache = false) {
let params = { id };
if (noCache) params.timestamp = new Date().getTime();
return request({ return request({
url: "/playlist/detail", url: "/playlist/detail",
method: "get", method: "get",
params: { params,
id,
},
}); });
} }
@ -63,3 +63,13 @@ export function toplists() {
method: "get", method: "get",
}); });
} }
export function subscribePlaylist(params) {
// 必选参数 :
// t : 类型,1:收藏,2:取消收藏 id : 歌单 id
return request({
url: "/playlist/subscribe",
method: "get",
params,
});
}

@ -1,4 +1,5 @@
import request from "@/utils/request"; import request from "@/utils/request";
import { mapTrackPlayableStatus } from "@/utils/common";
export function getMP3(id) { export function getMP3(id) {
return request({ return request({
@ -17,6 +18,9 @@ export function getTrackDetail(id) {
params: { params: {
ids: id, ids: id,
}, },
}).then((data) => {
data.songs = mapTrackPlayableStatus(data.songs);
return data;
}); });
} }
@ -45,3 +49,25 @@ export function topSong(type) {
}, },
}); });
} }
export function likeATrack(params) {
// 必选参数: id: 歌曲 id
// 可选参数 : like: 布尔值 , 默认为 true 即喜欢 , 若传 false, 则取消喜欢
params.timestamp = new Date().getTime();
return request({
url: "/like",
method: "get",
params,
});
}
export function scrobble(params) {
// 必选参数 : id: 歌曲 id, sourceid: 歌单或专辑 id
// 可选参数 : time: 歌曲播放时间,单位为秒
params.timestamp = new Date().getTime();
return request({
url: "/scrobble",
method: "get",
params,
});
}

@ -38,6 +38,9 @@ export function userLikedSongsIDs(uid) {
return request({ return request({
url: "/likelist", url: "/likelist",
method: "get", method: "get",
params: {
uid, uid,
timestamp: new Date().getTime(),
},
}); });
} }

@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="heart" class="svg-inline--fa fa-heart fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path></svg>

After

Width:  |  Height:  |  Size: 437 B

@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="heart" class="svg-inline--fa fa-heart fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M458.4 64.3C400.6 15.7 311.3 23 256 79.3 200.7 23 111.4 15.6 53.6 64.3-21.6 127.6-10.6 230.8 43 285.5l175.4 178.7c10 10.2 23.4 15.9 37.6 15.9 14.3 0 27.6-5.6 37.6-15.8L469 285.6c53.5-54.7 64.7-157.9-10.6-221.3zm-23.6 187.5L259.4 430.5c-2.4 2.4-4.4 2.4-6.8 0L77.2 251.8c-36.5-37.2-43.9-107.6 7.3-150.7 38.9-32.7 98.9-27.8 136.5 10.5l35 35.7 35-35.7c37.8-38.5 97.8-43.2 136.5-10.6 51.1 43.1 43.5 113.9 7.3 150.8z"></path></svg>

After

Width:  |  Height:  |  Size: 640 B

@ -27,18 +27,10 @@ button {
margin-left: 0; margin-left: 0;
} }
&:hover { &:hover {
// background: #eaeffd;
// .svg-icon {
// color: #335eea;
// }
background: #f5f5f7; background: #f5f5f7;
} }
&:active { &:active {
transform: scale(0.92); transform: scale(0.92);
// background: #eaeffd;
// .svg-icon {
// color: #335eea;
// }
} }
} }
</style> </style>

@ -1,5 +1,5 @@
<template> <template>
<button :style="{ padding: `8px ${horizontalPadding}px` }" :class="color"> <button :style="buttonStyle" :class="color">
<svg-icon <svg-icon
v-if="iconClass !== null" v-if="iconClass !== null"
:iconClass="iconClass" :iconClass="iconClass"
@ -29,6 +29,20 @@ export default {
type: String, type: String,
default: "blue", default: "blue",
}, },
shape: {
type: String,
default: "square",
},
},
computed: {
buttonStyle() {
return {
borderRadius: this.shape === "round" ? "50%" : "8px",
padding: `8px ${this.horizontalPadding}px`,
height: "38px",
width: this.shape === "round" ? "38px" : "auto",
};
},
}, },
}; };
</script> </script>
@ -37,11 +51,11 @@ export default {
button { button {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center;
font-size: 18px; font-size: 18px;
font-weight: 600; font-weight: 600;
background-color: rgba(51, 94, 234, 0.1); background-color: rgba(51, 94, 234, 0.1);
color: #335eea; color: #335eea;
border-radius: 8px;
margin-right: 12px; margin-right: 12px;
transition: 0.2s; transition: 0.2s;
.svg-icon { .svg-icon {
@ -59,4 +73,7 @@ button.grey {
background-color: #f5f5f7; background-color: #f5f5f7;
color: rgba(0, 0, 0, 0.5); color: rgba(0, 0, 0, 0.5);
} }
button.transparent {
background-color: transparent;
}
</style> </style>

@ -17,28 +17,35 @@
</div> </div>
<div class="controls"> <div class="controls">
<div class="playing"> <div class="playing">
<router-link :to="`/album/${player.currentTrack.album.id}`" <router-link :to="`/album/${currentTrack.al.id}`"
><img :src="player.currentTrack.album.picUrl | resizeImage" /> ><img :src="currentTrack.al.picUrl | resizeImage" />
</router-link> </router-link>
<div class="track-info"> <div class="track-info">
<div class="name"> <div class="name">
<router-link <router-link
:to="'/' + player.listInfo.type + '/' + player.listInfo.id" :to="'/' + player.listInfo.type + '/' + player.listInfo.id"
>{{ player.currentTrack.name }}</router-link >{{ currentTrack.name }}</router-link
> >
</div> </div>
<div class="artist"> <div class="artist">
<span <span v-for="(ar, index) in currentTrack.ar" :key="ar.id">
v-for="(ar, index) in player.currentTrack.artists"
:key="ar.id"
>
<router-link :to="`/artist/${ar.id}`">{{ ar.name }}</router-link> <router-link :to="`/artist/${ar.id}`">{{ ar.name }}</router-link>
<span v-if="index !== player.currentTrack.artists.length - 1" <span v-if="index !== currentTrack.ar.length - 1">, </span>
>,
</span>
</span> </span>
</div> </div>
</div> </div>
<div class="like-button" v-show="isLoggedIn">
<button-icon @click.native="likeCurrentSong">
<svg-icon
icon-class="heart"
v-show="!liked.songs.includes(currentTrack.id)"
></svg-icon>
<svg-icon
icon-class="heart-solid"
v-show="liked.songs.includes(currentTrack.id)"
></svg-icon>
</button-icon>
</div>
</div> </div>
<div class="middle-control-buttons"> <div class="middle-control-buttons">
<button-icon @click.native="previous" title="Previous Song" <button-icon @click.native="previous" title="Previous Song"
@ -106,6 +113,9 @@
<script> <script>
import { updateMediaSessionMetaData } from "@/utils/mediaSession"; import { updateMediaSessionMetaData } from "@/utils/mediaSession";
import { mapState, mapMutations, mapActions } from "vuex"; import { mapState, mapMutations, mapActions } from "vuex";
import { isLoggedIn } from "@/utils/auth";
import { userLikedSongsIDs } from "@/api/user";
import { likeATrack } from "@/api/track";
import "@/assets/css/slider.css"; import "@/assets/css/slider.css";
import ButtonIcon from "@/components/ButtonIcon.vue"; import ButtonIcon from "@/components/ButtonIcon.vue";
@ -128,9 +138,17 @@ export default {
setInterval(() => { setInterval(() => {
this.progress = ~~this.howler.seek(); this.progress = ~~this.howler.seek();
}, 1000); }, 1000);
if (this.isLoggedIn) {
userLikedSongsIDs(this.settings.user.userId).then((data) => {
this.updateLikedSongs(data.ids);
});
}
}, },
computed: { computed: {
...mapState(["player", "howler", "Howler"]), ...mapState(["player", "howler", "Howler", "settings", "liked"]),
currentTrack() {
return this.player.currentTrack;
},
volume: { volume: {
get() { get() {
return this.player.volume; return this.player.volume;
@ -147,9 +165,12 @@ export default {
return this.howler.playing(); return this.howler.playing();
}, },
progressMax() { progressMax() {
let max = ~~(this.player.currentTrack.time / 1000); let max = ~~(this.currentTrack.dt / 1000);
return max > 1 ? max - 1 : max; return max > 1 ? max - 1 : max;
}, },
isLoggedIn() {
return isLoggedIn();
},
}, },
methods: { methods: {
...mapMutations([ ...mapMutations([
@ -158,6 +179,7 @@ export default {
"shuffleTheList", "shuffleTheList",
"updatePlayerState", "updatePlayerState",
"updateRepeatStatus", "updateRepeatStatus",
"updateLikedSongs",
]), ]),
...mapActions([ ...mapActions([
"nextTrack", "nextTrack",
@ -170,22 +192,22 @@ export default {
this.howler.pause(); this.howler.pause();
} else { } else {
if (this.howler.state() === "unloaded") { if (this.howler.state() === "unloaded") {
this.playTrackOnListByID(this.player.currentTrack.id); this.playTrackOnListByID(this.currentTrack.id);
} }
this.howler.play(); this.howler.play();
if (this.howler._onend.length === 0) { if (this.howler._onend.length === 0) {
this.addNextTrackEvent(); this.addNextTrackEvent();
updateMediaSessionMetaData(this.player.currentTrack); updateMediaSessionMetaData(this.currentTrack);
} }
} }
}, },
next() { next() {
this.nextTrack(true);
this.progress = 0; this.progress = 0;
this.nextTrack(true);
}, },
previous() { previous() {
this.previousTrack();
this.progress = 0; this.progress = 0;
this.previousTrack();
}, },
shuffle() { shuffle() {
if (this.player.shuffle === true) { if (this.player.shuffle === true) {
@ -228,6 +250,20 @@ export default {
let sec = (~~(value % 60)).toString().padStart(2, "0"); let sec = (~~(value % 60)).toString().padStart(2, "0");
return `${min}:${sec}`; return `${min}:${sec}`;
}, },
likeCurrentSong() {
let id = this.currentTrack.id;
let like = true;
if (this.liked.songs.includes(id)) like = false;
likeATrack({ id, like }).then(() => {
if (like === false) {
this.updateLikedSongs(this.liked.songs.filter((d) => d !== id));
} else {
let newLikeSongs = this.liked.songs;
newLikeSongs.push(id);
this.updateLikedSongs(newLikeSongs);
}
});
},
}, },
}; };
</script> </script>
@ -289,6 +325,7 @@ export default {
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
-webkit-line-clamp: 1; -webkit-line-clamp: 1;
overflow: hidden; overflow: hidden;
word-break: break-all;
&:hover { &:hover {
text-decoration: underline; text-decoration: underline;
} }
@ -300,6 +337,7 @@ export default {
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
-webkit-line-clamp: 1; -webkit-line-clamp: 1;
overflow: hidden; overflow: hidden;
word-break: break-all;
a { a {
cursor: pointer; cursor: pointer;
&:hover { &:hover {
@ -319,11 +357,11 @@ export default {
margin: 0 8px; margin: 0 8px;
} }
.play { .play {
height: 48px; height: 42px;
width: 48px; width: 42px;
.svg-icon { .svg-icon {
width: 28px; width: 24px;
height: 28px; height: 24px;
} }
} }
} }
@ -351,4 +389,8 @@ export default {
} }
} }
} }
.like-button {
margin-left: 16px;
}
</style> </style>

@ -15,7 +15,7 @@
</template> </template>
<script> <script>
import { mapActions } from "vuex"; import { mapActions, mapState } from "vuex";
import { import {
playPlaylistByID, playPlaylistByID,
playAlbumByID, playAlbumByID,
@ -42,7 +42,7 @@ export default {
}, },
dbclickTrackFunc: { dbclickTrackFunc: {
type: String, type: String,
default: "none", default: "default",
}, },
}, },
data() { data() {
@ -55,8 +55,11 @@ export default {
if (this.type === "tracklist") if (this.type === "tracklist")
this.listStyles = { display: "flex", flexWrap: "wrap" }; this.listStyles = { display: "flex", flexWrap: "wrap" };
}, },
computed: {
...mapState(["liked"]),
},
methods: { methods: {
...mapActions(["nextTrack"]), ...mapActions(["nextTrack", "playTrackOnListByID"]),
openMenu(e, track) { openMenu(e, track) {
if (!track.playable) { if (!track.playable) {
return; return;
@ -65,24 +68,31 @@ export default {
this.$refs.menu.openMenu(e); this.$refs.menu.openMenu(e);
}, },
playThisList(trackID) { playThisList(trackID) {
if (this.dbclickTrackFunc === "default") {
this.playThisListDefault(trackID);
} else if (this.dbclickTrackFunc === "none") {
// do nothing
} else if (this.dbclickTrackFunc === "playTrackOnListByID") {
this.playTrackOnListByID(trackID);
} else if (this.dbclickTrackFunc === "playPlaylistByID") {
playPlaylistByID(this.id, trackID);
}
},
playThisListDefault(trackID) {
if (this.type === "playlist") { if (this.type === "playlist") {
playPlaylistByID(this.id, trackID); playPlaylistByID(this.id, trackID);
} else if (this.type === "album") { } else if (this.type === "album") {
playAlbumByID(this.id, trackID); playAlbumByID(this.id, trackID);
} else if (this.type === "tracklist") { } else if (this.type === "tracklist") {
if (this.dbclickTrackFunc === "none") { let trackIDs = this.tracks.map((t) => t.id);
playAList(this.tracks, this.tracks[0].ar[0].id, "artist", trackID); playAList(trackIDs, this.tracks[0].ar[0].id, "artist", trackID);
} else {
if (this.dbclickTrackFunc === "playPlaylistByID")
playPlaylistByID(this.id, trackID);
}
} }
}, },
play() { play() {
appendTrackToPlayerList(this.clickTrack, true); appendTrackToPlayerList(this.clickTrack.id, true);
}, },
playNext() { playNext() {
appendTrackToPlayerList(this.clickTrack); appendTrackToPlayerList(this.clickTrack.id);
}, },
}, },
}; };

@ -1,7 +1,22 @@
<template> <template>
<div class="track" :class="trackClass" :style="trackStyle"> <div
class="track"
:class="trackClass"
:style="trackStyle"
@mouseover="focus = true"
@mouseleave="focus = false"
>
<img :src="imgUrl | resizeImage" v-if="!isAlbum" @click="goToAlbum" /> <img :src="imgUrl | resizeImage" v-if="!isAlbum" @click="goToAlbum" />
<div class="no" v-if="isAlbum">{{ track.no }}</div> <div class="no" v-if="isAlbum">
<button
class="play-button"
v-show="focus && track.playable"
@click="playTrack"
>
<svg-icon icon-class="play"></svg-icon>
</button>
<span v-show="!focus">{{ track.no }}</span>
</div>
<div class="title-and-artist"> <div class="title-and-artist">
<div class="container"> <div class="container">
<div class="title"> <div class="title">
@ -18,7 +33,7 @@
<span <span
v-if="track.mark === 1318912" v-if="track.mark === 1318912"
class="explicit-symbol before-artist" class="explicit-symbol before-artist"
><ExplicitSymbol ><ExplicitSymbol :size="15"
/></span> /></span>
<ArtistsInLine :artists="artists" /> <ArtistsInLine :artists="artists" />
</div> </div>
@ -26,13 +41,23 @@
<div></div> <div></div>
</div> </div>
<div class="album" v-if="!isTracklist && !isAlbum"> <div class="album" v-if="!isTracklist && !isAlbum">
<div class="container">
<router-link :to="`/album/${track.al.id}`">{{ <router-link :to="`/album/${track.al.id}`">{{
track.al.name track.al.name
}}</router-link> }}</router-link>
</div>
<div></div> <div></div>
</div> </div>
<div class="actions" v-if="!isTracklist">
<button v-if="isLoggedIn" @click="likeThisSong">
<svg-icon
icon-class="heart"
:style="{
visibility:
focus && !isLiked && track.playable ? 'visible' : 'hidden',
}"
></svg-icon>
<svg-icon icon-class="heart-solid" v-show="isLiked"></svg-icon>
</button>
</div>
<div class="time" v-if="!isTracklist"> <div class="time" v-if="!isTracklist">
{{ track.dt | formatTime }} {{ track.dt | formatTime }}
</div> </div>
@ -40,6 +65,9 @@
</template> </template>
<script> <script>
import { isLoggedIn } from "@/utils/auth";
import { likeATrack } from "@/api/track";
import ArtistsInLine from "@/components/ArtistsInLine.vue"; import ArtistsInLine from "@/components/ArtistsInLine.vue";
import ExplicitSymbol from "@/components/ExplicitSymbol.vue"; import ExplicitSymbol from "@/components/ExplicitSymbol.vue";
@ -50,16 +78,7 @@ export default {
track: Object, track: Object,
}, },
data() { data() {
return { return { focus: false, trackStyle: {} };
trackClass: [],
trackStyle: {},
};
},
created() {
this.trackClass.push(this.type);
if (!this.track.playable) this.trackClass.push("disable");
if (this.$parent.itemWidth !== -1)
this.trackStyle = { width: this.$parent.itemWidth + "px" };
}, },
computed: { computed: {
imgUrl() { imgUrl() {
@ -84,16 +103,82 @@ export default {
isPlaylist() { isPlaylist() {
return this.type === "playlist"; return this.type === "playlist";
}, },
isLiked() {
return this.$parent.liked.songs.includes(this.track.id);
},
isPlaying() {
return this.$store.state.player.currentTrack.id === this.track.id;
},
trackClass() {
let trackClass = [this.type];
if (!this.track.playable) trackClass.push("disable");
if (this.isPlaying) trackClass.push("playing");
return trackClass;
},
isLoggedIn() {
return isLoggedIn();
},
}, },
methods: { methods: {
goToAlbum() { goToAlbum() {
this.$router.push({ path: "/album/" + this.track.al.id }); this.$router.push({ path: "/album/" + this.track.al.id });
}, },
playTrack() {
this.$parent.playThisList(this.track.id);
},
likeThisSong() {
let id = this.track.id;
let like = true;
let likedSongs = this.$parent.liked.songs;
if (likedSongs.includes(id)) like = false;
likeATrack({ id, like }).then(() => {
if (like === false) {
this.$store.commit(
"updateLikedSongs",
likedSongs.filter((d) => d !== id)
);
} else {
likedSongs.push(id);
this.$store.commit("updateLikedSongs", likedSongs);
}
});
},
},
created() {
if (this.$parent.itemWidth !== -1)
this.trackStyle = { width: this.$parent.itemWidth + "px" };
}, },
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
button {
display: flex;
justify-content: center;
align-items: center;
padding: 8px;
background: transparent;
border-radius: 25%;
transition: transform 0.2s;
.svg-icon {
height: 16px;
width: 16px;
color: #335eea;
}
&:active {
transform: scale(0.92);
}
}
button.play-button {
opacity: 1;
.svg-icon {
height: 14px;
width: 14px;
color: #335eea;
}
}
.track { .track {
display: flex; display: flex;
align-items: center; align-items: center;
@ -182,20 +267,12 @@ export default {
.album { .album {
flex: 1; flex: 1;
display: flex; display: flex;
font-size: 16px;
color: rgba(0, 0, 0, 0.88);
display: -webkit-box; display: -webkit-box;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
-webkit-line-clamp: 2; -webkit-line-clamp: 2;
overflow: hidden; overflow: hidden;
.container {
display: flex;
flex-direction: column;
&:hover {
text-decoration: underline;
cursor: pointer;
}
}
font-size: 16px;
color: rgba(0, 0, 0, 0.88);
} }
.time { .time {
font-size: 16px; font-size: 16px;
@ -247,4 +324,32 @@ export default {
.track.album { .track.album {
height: 32px; height: 32px;
} }
.actions {
width: 80px;
display: flex;
justify-content: flex-end;
}
.track.playing {
background: #eaeffd;
color: #335eea;
.title,
.album {
color: #335eea;
}
.title .featured,
.artist {
color: #335eea;
opacity: 0.88;
}
.no span {
color: #335eea;
opacity: 0.78;
}
.explicit-symbol {
color: #335eea;
opacity: 0.88;
}
}
</style> </style>

@ -1,17 +1,31 @@
// import { getMP3 } from "@/api/track"; // import { getMP3 } from "@/api/track";
import { updateMediaSessionMetaData } from "@/utils/mediaSession"; import { updateMediaSessionMetaData } from "@/utils/mediaSession";
import { getTrackDetail, scrobble } from "@/api/track";
export default { export default {
switchTrack({ state, dispatch, commit }, track) { switchTrack({ state, dispatch, commit }, basicTrack) {
commit("updateCurrentTrack", track); getTrackDetail(basicTrack.id).then((data) => {
let track = data.songs[0];
track.sort = basicTrack.sort;
console.log(track);
if (track.playable === false) { if (track.playable === false) {
dispatch("nextTrack"); dispatch("nextTrack");
return; return;
} }
let time = state.howler.seek();
scrobble({
id: state.player.currentTrack.id,
sourceid: state.player.listInfo.id,
time: time === 0 ? 180 : time,
}).then((data) => {
console.log("scrobble", data);
});
commit("updateCurrentTrack", track);
updateMediaSessionMetaData(track); updateMediaSessionMetaData(track);
document.title = `${track.name} · ${track.artists[0].name} - YesPlayMusic`; document.title = `${track.name} · ${track.ar[0].name} - YesPlayMusic`;
commit( commit(
"replaceMP3", "replaceMP3",
@ -20,13 +34,13 @@ export default {
state.howler.once("end", () => { state.howler.once("end", () => {
dispatch("nextTrack"); dispatch("nextTrack");
}); });
});
}, },
playFirstTrackOnList({ state, dispatch }) { playFirstTrackOnList({ state, dispatch }) {
dispatch("switchTrack", state.player.list[0]); dispatch("switchTrack", state.player.list[0]);
}, },
playTrackOnListByID(context, trackID) { playTrackOnListByID(context, trackID) {
let track = context.state.player.list.find((t) => t.id === trackID); let track = context.state.player.list.find((t) => t.id === trackID);
if (track.playable === false) return;
context.dispatch("switchTrack", track); context.dispatch("switchTrack", track);
}, },
nextTrack({ state, dispatch }, realNext = false) { nextTrack({ state, dispatch }, realNext = false) {

@ -3,6 +3,9 @@ import { Howler } from "howler";
const initState = { const initState = {
Howler: Howler, Howler: Howler,
howler: null, howler: null,
liked: {
songs: [],
},
contextMenu: { contextMenu: {
clickObjectID: 0, clickObjectID: 0,
showMenu: false, showMenu: false,
@ -82,7 +85,7 @@ const initState = {
}, },
], ],
user: { user: {
id: 1, id: 0,
}, },
}, },
}; };

@ -86,4 +86,7 @@ export default {
updateUserInfo(sate, { key, value }) { updateUserInfo(sate, { key, value }) {
state.settings.user[key] = value; state.settings.user[key] = value;
}, },
updateLikedSongs(state, trackIDs) {
state.liked.songs = trackIDs;
},
}; };

@ -3,6 +3,9 @@ import { Howler } from "howler";
export default { export default {
Howler: Howler, Howler: Howler,
howler: null, howler: null,
liked: {
songs: [],
},
contextMenu: { contextMenu: {
clickObjectID: 0, clickObjectID: 0,
showMenu: false, showMenu: false,

@ -61,6 +61,14 @@ Vue.filter("formatPlayCount", (count) => {
return `${~~(count / 10000)}`; return `${~~(count / 10000)}`;
} }
return count; return count;
// if (count > 1000000) {
// return `${Math.floor((count / 1000000) * 100) / 100}M`;
// }
// if (count > 1000) {
// return `${~~(count / 1000)}K`;
// }
// return count;
}); });
Vue.filter("toHttps", (url) => { Vue.filter("toHttps", (url) => {

@ -22,14 +22,14 @@ export function initMediaSession() {
export function updateMediaSessionMetaData(track) { export function updateMediaSessionMetaData(track) {
if ("mediaSession" in navigator) { if ("mediaSession" in navigator) {
let artists = track.artists.map((a) => a.name); let artists = track.ar.map((a) => a.name);
navigator.mediaSession.metadata = new window.MediaMetadata({ navigator.mediaSession.metadata = new window.MediaMetadata({
title: track.name, title: track.name,
artist: artists.join(","), artist: artists.join(","),
album: track.album.name, album: track.al.name,
artwork: [ artwork: [
{ {
src: track.album.picUrl + "?param=512y512", src: track.al.picUrl + "?param=512y512",
type: "image/jpg", type: "image/jpg",
sizes: "512x512", sizes: "512x512",
}, },

@ -1,23 +1,12 @@
import store from "@/store"; import store from "@/store";
import { getAlbum } from "@/api/album"; import { getAlbum } from "@/api/album";
import { getPlaylistDetail } from "@/api/playlist"; import { getPlaylistDetail } from "@/api/playlist";
import { getTrackDetail } from "@/api/track";
import { getArtist } from "@/api/artist"; import { getArtist } from "@/api/artist";
import { isTrackPlayable } from "@/utils/common";
export function playAList(list, id, type, trackID = "first") { export function playAList(list, id, type, trackID = "first") {
let filteredList = list.map((track, index) => { let filteredList = list.map((id, index) => {
return { return { sort: index, id };
sort: index,
name: track.name,
id: track.id,
artists: track.ar,
album: track.al,
time: track.dt,
playable: isTrackPlayable(track).playable,
};
}); });
store.commit("updatePlayerList", filteredList); store.commit("updatePlayerList", filteredList);
if (trackID === "first") store.dispatch("playFirstTrackOnList"); if (trackID === "first") store.dispatch("playFirstTrackOnList");
@ -28,16 +17,15 @@ export function playAList(list, id, type, trackID = "first") {
export function playAlbumByID(id, trackID = "first") { export function playAlbumByID(id, trackID = "first") {
getAlbum(id).then((data) => { getAlbum(id).then((data) => {
playAList(data.songs, id, "album", trackID); let trackIDs = data.songs.map((t) => t.id);
playAList(trackIDs, id, "album", trackID);
}); });
} }
export function playPlaylistByID(id, trackID = "first") { export function playPlaylistByID(id, trackID = "first", noCache = false) {
getPlaylistDetail(id).then((data) => { getPlaylistDetail(id, noCache).then((data) => {
let trackIDs = data.playlist.trackIds.map((t) => t.id); let trackIDs = data.playlist.trackIds.map((t) => t.id);
getTrackDetail(trackIDs.join(",")).then((data) => { playAList(trackIDs, id, "playlist", trackID);
playAList(data.songs, id, "playlist", trackID);
});
}); });
} }
@ -47,15 +35,10 @@ export function playArtistByID(id, trackID = "first") {
}); });
} }
export function appendTrackToPlayerList(track, playNext = false) { export function appendTrackToPlayerList(trackID, playNext = false) {
let filteredTrack = { let filteredTrack = {
sort: 0, sort: 0,
name: track.name, id: trackID,
id: track.id,
artists: track.ar,
album: track.al,
time: track.dt,
playable: track.playable,
}; };
store.commit("appendTrackToPlayerList", { store.commit("appendTrackToPlayerList", {

@ -76,7 +76,6 @@ import { mapMutations, mapActions, mapState } from "vuex";
import NProgress from "nprogress"; import NProgress from "nprogress";
import { getTrackDetail } from "@/api/track"; import { getTrackDetail } from "@/api/track";
import { playAlbumByID } from "@/utils/play"; import { playAlbumByID } from "@/utils/play";
import { mapTrackPlayableStatus } from "@/utils/common";
import { getAlbum } from "@/api/album"; import { getAlbum } from "@/api/album";
import ExplicitSymbol from "@/components/ExplicitSymbol.vue"; import ExplicitSymbol from "@/components/ExplicitSymbol.vue";
@ -111,17 +110,15 @@ export default {
.then((data) => { .then((data) => {
this.album = data.album; this.album = data.album;
this.tracks = data.songs; this.tracks = data.songs;
this.tracks = mapTrackPlayableStatus(this.tracks);
NProgress.done(); NProgress.done();
this.show = true; this.show = true;
return this.tracks; return this.tracks;
}) })
.then((tracks) => { .then((tracks) => {
// to get explicit mark
let trackIDs = tracks.map((t) => t.id); let trackIDs = tracks.map((t) => t.id);
getTrackDetail(trackIDs.join(",")).then((data) => { getTrackDetail(trackIDs.join(",")).then((data) => {
this.tracks = data.songs; this.tracks = data.songs;
this.tracks = mapTrackPlayableStatus(this.tracks);
}); });
}); });
}, },

@ -170,7 +170,8 @@ export default {
}); });
}, },
playPopularSongs(trackID = "first") { playPopularSongs(trackID = "first") {
playAList(this.popularTracks, this.artist.id, "artist", trackID); let trackIDs = this.popularTracks.map((t) => t.id);
playAList(trackIDs, this.artist.id, "artist", trackID);
}, },
}, },
created() { created() {

@ -20,7 +20,9 @@
<div class="bottom"> <div class="bottom">
<div class="titles"> <div class="titles">
<div class="title">Liked Songs</div> <div class="title">Liked Songs</div>
<div class="sub-title">{{ likedSongs.trackCount }} songs</div> <div class="sub-title">
{{ likedSongsPlaylist.trackCount }} songs
</div>
</div> </div>
<button @click.stop="playLikedSongs"> <button @click.stop="playLikedSongs">
<svg-icon icon-class="play" /> <svg-icon icon-class="play" />
@ -29,10 +31,10 @@
</div> </div>
<div class="songs"> <div class="songs">
<TrackList <TrackList
:tracks="likedSongs.tracks" :tracks="likedSongs"
:type="'tracklist'" :type="'tracklist'"
:itemWidth="220" :itemWidth="220"
:id="likedSongs.id" :id="likedSongsPlaylist.id"
dbclickTrackFunc="playPlaylistByID" dbclickTrackFunc="playPlaylistByID"
/> />
</div> </div>
@ -79,7 +81,12 @@ export default {
}, },
playlists: [], playlists: [],
hasMorePlaylists: true, hasMorePlaylists: true,
likedSongsPlaylist: {
id: 0,
trackCount: 0,
},
likedSongs: [], likedSongs: [],
likedSongIDs: [],
lyric: undefined, lyric: undefined,
}; };
}, },
@ -94,6 +101,9 @@ export default {
}, },
computed: { computed: {
...mapState(["settings"]), ...mapState(["settings"]),
likedSongsInState() {
return this.$store.state.liked.songs;
},
pickedLyric() { pickedLyric() {
if (this.lyric === undefined) return ""; if (this.lyric === undefined) return "";
let lyric = this.lyric.split("\n"); let lyric = this.lyric.split("\n");
@ -116,7 +126,7 @@ export default {
}, },
methods: { methods: {
playLikedSongs() { playLikedSongs() {
playPlaylistByID(this.likedSongs.id); playPlaylistByID(this.playlists[0].id, "first", true);
}, },
goToLikedSongsList() { goToLikedSongsList() {
this.$router.push({ path: "/library/liked-songs" }); this.$router.push({ path: "/library/liked-songs" });
@ -126,42 +136,43 @@ export default {
userPlaylist({ userPlaylist({
uid: this.settings.user.userId, uid: this.settings.user.userId,
offset: this.playlists.length, offset: this.playlists.length,
timestamp: new Date().getTime(),
}).then((data) => { }).then((data) => {
this.playlists.push(...data.playlist); this.playlists.push(...data.playlist);
this.hasMorePlaylists = data.more; this.hasMorePlaylists = data.more;
this.likedSongsPlaylist = data.playlist[0];
}); });
} }
this.getLikedSongs(); this.getLikedSongs();
}, },
getLikedSongs() { getLikedSongs(getLyric = true) {
getPlaylistDetail(this.settings.user.likedSongPlaylistID).then((data) => { getPlaylistDetail(this.settings.user.likedSongPlaylistID, true).then(
let oldTracks = this.likedSongs.tracks; (data) => {
this.likedSongs = data.playlist; let TrackIDs = data.playlist.trackIds.slice(0, 20).map((t) => t.id);
this.likedSongs.tracks = oldTracks; this.likedSongIDs = TrackIDs;
getTrackDetail(this.likedSongIDs.join(",")).then((data) => {
this.getMoreLikedSongs(); this.likedSongs = data.songs;
this.getRandomLyric(); this.likedSongs = mapTrackPlayableStatus(this.likedSongs);
});
},
getMoreLikedSongs() {
let TrackIDs = this.likedSongs.trackIds.slice(0, 20).map((t) => t.id);
getTrackDetail(TrackIDs.join(",")).then((data) => {
this.likedSongs.tracks = data.songs;
this.likedSongs.tracks = mapTrackPlayableStatus(this.likedSongs.tracks);
NProgress.done(); NProgress.done();
this.show = true; this.show = true;
}); });
if (getLyric) this.getRandomLyric();
}
);
}, },
getRandomLyric() { getRandomLyric() {
getLyric( getLyric(
this.likedSongs.trackIds[ this.likedSongIDs[randomNum(0, this.likedSongIDs.length - 1)]
randomNum(0, this.likedSongs.trackIds.length - 1)
].id
).then((data) => { ).then((data) => {
if (data.lrc !== undefined) this.lyric = data.lrc.lyric; if (data.lrc !== undefined) this.lyric = data.lrc.lyric;
}); });
}, },
}, },
watch: {
likedSongsInState() {
this.getLikedSongs(false);
},
},
}; };
</script> </script>

@ -13,7 +13,8 @@
{{ mv.data.name }} {{ mv.data.name }}
</div> </div>
<div class="info"> <div class="info">
{{ mv.data.playCount }} Views · {{ mv.data.publishTime }} {{ mv.data.playCount | formatPlayCount }} Views ·
{{ mv.data.publishTime }}
</div> </div>
</div> </div>
</div> </div>

@ -1,94 +1,43 @@
<template> <template>
<div class="next-tracks"> <div class="next-tracks">
<h1>Now Playing</h1> <h1>Now Playing</h1>
<div class="track-list"> <TrackList
<div class="track playing"> :tracks="[currentTrack]"
<img :src="currentTrack.album.picUrl | resizeImage" /> :type="'playlist'"
<div class="title-and-artist"> dbclickTrackFunc="none"
<div class="container"> />
<div class="title">
{{ currentTrack.name }}
</div>
<div class="artist">
<span v-for="(ar, index) in currentTrack.artists" :key="ar.id">
<router-link :to="`/artist/${ar.id}`">{{ ar.name }}</router-link
><span v-if="index !== currentTrack.artists.length - 1"
>,
</span>
</span>
</div>
</div>
<div></div>
</div>
<div class="album">
<div class="container">
<router-link :to="`/album/${currentTrack.album.id}`">{{
currentTrack.album.name
}}</router-link>
</div>
<div></div>
</div>
<div class="time">
{{ currentTrack.time | formatTime }}
</div>
</div>
</div>
<h1>Next Up</h1> <h1>Next Up</h1>
<div class="track-list">
<div <TrackList
class="track" :tracks="sortedTracks"
v-for="track in tracks" :type="'playlist'"
:class="{ disable: !track.playable }" dbclickTrackFunc="playTrackOnListByID"
:title="!track.playable ? track.reason : ''" />
:key="`${track.id}-${track.sort}`"
@dblclick="playTrackOnListByID(track.id)"
>
<img :src="track.album.picUrl | resizeImage" />
<div class="title-and-artist">
<div class="container">
<div class="title">
{{ track.name }}
</div>
<div class="artist">
<span v-for="(ar, index) in track.artists" :key="ar.id">
<router-link :to="`/artist/${ar.id}`">{{ ar.name }}</router-link
><span v-if="index !== track.artists.length - 1">, </span>
</span>
</div>
</div>
<div></div>
</div>
<div class="album">
<div class="container">
<router-link :to="`/album/${track.album.id}`">{{
track.album.name
}}</router-link>
</div>
<div></div>
</div>
<div class="time">
{{ parseInt((track.time % (1000 * 60 * 60)) / (1000 * 60)) }}:{{
parseInt((track.time % (1000 * 60)) / 1000)
.toString()
.padStart(2, "0")
}}
</div>
</div>
</div>
</div> </div>
</template> </template>
<script> <script>
import { mapState, mapActions } from "vuex"; import { mapState, mapActions } from "vuex";
import { getTrackDetail } from "@/api/track";
import TrackList from "@/components/TrackList.vue";
export default { export default {
name: "Next", name: "Next",
components: {
TrackList,
},
data() {
return {
tracks: [],
showTracks: [],
};
},
computed: { computed: {
...mapState(["player"]), ...mapState(["player"]),
currentTrack() { currentTrack() {
return this.player.currentTrack; return this.player.currentTrack;
}, },
tracks() { sortedTracks() {
function compare(property) { function compare(property) {
return function(obj1, obj2) { return function(obj1, obj2) {
var value1 = obj1[property]; var value1 = obj1[property];
@ -96,15 +45,45 @@ export default {
return value1 - value2; return value1 - value2;
}; };
} }
return this.player.list let tracks = this.tracks
.filter( .filter((t) => t.sort > this.player.currentTrack.sort)
(t) => t.sort > this.player.currentTrack.sort // && t.playable === true
)
.sort(compare("sort")); .sort(compare("sort"));
return tracks;
},
},
watch: {
currentTrack() {
this.loadTracks();
}, },
}, },
methods: { methods: {
...mapActions(["playTrackOnListByID"]), ...mapActions(["playTrackOnListByID"]),
loadTracks() {
console.time("loadTracks");
let loadedTrackIDs = this.tracks.map((t) => t.id);
let basicTracks = this.player.list
.filter(
(t) =>
t.sort > this.player.currentTrack.sort &&
t.sort <= this.player.currentTrack.sort + 100
)
.filter((t) => loadedTrackIDs.includes(t.id) === false);
let trackIDs = basicTracks.map((t) => t.id);
if (trackIDs.length > 0) {
getTrackDetail(trackIDs.join(",")).then((data) => {
let newTracks = data.songs.map((t) => {
t.sort = this.player.list.find((t2) => t2.id == t.id).sort;
return t;
});
this.tracks.push(...newTracks);
});
}
console.timeEnd("loadTracks");
},
},
activated() {
this.loadTracks();
}, },
}; };
</script> </script>

@ -46,10 +46,14 @@
PLAY PLAY
</ButtonTwoTone> </ButtonTwoTone>
<ButtonTwoTone <ButtonTwoTone
@click.native="shufflePlay" v-if="
:iconClass="`shuffle`" isLoggedIn && playlist.creator.userId !== settings.user.userId
"
shape="round"
:iconClass="playlist.subscribed ? 'heart-solid' : 'heart'"
:iconButton="true" :iconButton="true"
:horizontalPadding="11" :horizontalPadding="0"
@click.native="likePlaylist"
> >
</ButtonTwoTone> </ButtonTwoTone>
</div> </div>
@ -76,10 +80,11 @@
<script> <script>
import { mapMutations, mapActions, mapState } from "vuex"; import { mapMutations, mapActions, mapState } from "vuex";
import NProgress from "nprogress"; import NProgress from "nprogress";
import { getPlaylistDetail } from "@/api/playlist"; import { getPlaylistDetail, subscribePlaylist } from "@/api/playlist";
import { playPlaylistByID } from "@/utils/play"; import { playAList } from "@/utils/play";
import { getTrackDetail } from "@/api/track"; import { getTrackDetail } from "@/api/track";
import { mapTrackPlayableStatus } from "@/utils/common"; import { mapTrackPlayableStatus } from "@/utils/common";
import { isLoggedIn } from "@/utils/auth";
import ButtonTwoTone from "@/components/ButtonTwoTone.vue"; import ButtonTwoTone from "@/components/ButtonTwoTone.vue";
import TrackList from "@/components/TrackList.vue"; import TrackList from "@/components/TrackList.vue";
@ -115,7 +120,10 @@ export default {
window.removeEventListener("scroll", this.handleScroll, true); window.removeEventListener("scroll", this.handleScroll, true);
}, },
computed: { computed: {
...mapState(["player"]), ...mapState(["player", "settings"]),
isLoggedIn() {
return isLoggedIn();
},
}, },
methods: { methods: {
...mapMutations([ ...mapMutations([
@ -125,16 +133,24 @@ export default {
]), ]),
...mapActions(["playFirstTrackOnList", "playTrackOnListByID"]), ...mapActions(["playFirstTrackOnList", "playTrackOnListByID"]),
playPlaylistByID(trackID = "first") { playPlaylistByID(trackID = "first") {
playPlaylistByID(this.playlist.id, trackID); let trackIDs = this.playlist.trackIds.map((t) => t.id);
playAList(trackIDs, this.playlist.id, "playlist", trackID);
}, },
shufflePlay() { likePlaylist() {
this.playPlaylistByID(); subscribePlaylist({
this.shuffleTheList(); id: this.playlist.id,
t: this.playlist.subscribed ? 2 : 1,
}).then((data) => {
if (data.code === 200)
this.playlist.subscribed = !this.playlist.subscribed;
getPlaylistDetail(this.id, true).then((data) => {
this.playlist = data.playlist;
});
});
}, },
loadData(id, next = undefined) { loadData(id, next = undefined) {
console.log("loadData");
this.id = id; this.id = id;
getPlaylistDetail(this.id) getPlaylistDetail(this.id, true)
.then((data) => { .then((data) => {
this.playlist = data.playlist; this.playlist = data.playlist;
this.tracks = data.playlist.tracks; this.tracks = data.playlist.tracks;
@ -142,6 +158,7 @@ export default {
NProgress.done(); NProgress.done();
if (next !== undefined) next(); if (next !== undefined) next();
this.show = true; this.show = true;
this.lastLoadedTrackIndex = data.playlist.tracks.length - 1;
if (this.playlist.trackCount > this.tracks.length) { if (this.playlist.trackCount > this.tracks.length) {
window.addEventListener("scroll", this.handleScroll, true); window.addEventListener("scroll", this.handleScroll, true);
} }
@ -233,26 +250,7 @@ export default {
margin-top: 32px; margin-top: 32px;
display: flex; display: flex;
button { button {
display: flex; margin-right: 16px;
align-items: center;
font-size: 18px;
font-weight: 600;
background-color: rgba(51, 94, 234, 0.1);
color: #335eea;
padding: 8px 16px;
border-radius: 8px;
margin-right: 12px;
.svg-icon {
width: 16px;
height: 16px;
margin-right: 8px;
}
}
.shuffle {
padding: 8px 11px;
.svg-icon {
margin: 0;
}
} }
} }
} }

@ -73,7 +73,7 @@
<TrackList :tracks="tracks" :type="'tracklist'" /> <TrackList :tracks="tracks" :type="'tracklist'" />
</div> </div>
<div class="mvs" v-if="mvs.length > 0"> <div class="mvs" v-if="mvs !== null && mvs.length > 0">
<div class="section-title">MVs</div> <div class="section-title">MVs</div>
<MvRow class="mv-row" :mvs="mvs.slice(0, 5)" /> <MvRow class="mv-row" :mvs="mvs.slice(0, 5)" />
</div> </div>
@ -119,7 +119,6 @@
import { mapState } from "vuex"; import { mapState } from "vuex";
import NProgress from "nprogress"; import NProgress from "nprogress";
import { appendTrackToPlayerList } from "@/utils/play"; import { appendTrackToPlayerList } from "@/utils/play";
import { mapTrackPlayableStatus } from "@/utils/common";
import { search } from "@/api/others"; import { search } from "@/api/others";
import Cover from "@/components/Cover.vue"; import Cover from "@/components/Cover.vue";
@ -149,7 +148,7 @@ export default {
return this.$route.query.keywords; return this.$route.query.keywords;
}, },
tracks() { tracks() {
let tracks = mapTrackPlayableStatus(this.result.song.songs.slice(0, 12)); let tracks = this.result.song.songs.slice(0, 12);
return tracks; return tracks;
}, },
}, },

Loading…
Cancel
Save