mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 12:47:27 +08:00
fix : PersonalFM can not found next track (#1217)
* fix : PersonalFM can not found next track * do not call _loadPersonalFMNextTrack() when reload personal FM * fix: revert * fix: separate playNextTrack * fix: moveToFMTrash * fix * fix: shortcut and _loadPersonalFMNextTrack() * show toast when personal timeout * fix: name
This commit is contained in:
parent
c7c6583523
commit
3ea5446fcc
|
@ -74,8 +74,11 @@ export default {
|
||||||
this.player.playPersonalFM();
|
this.player.playPersonalFM();
|
||||||
},
|
},
|
||||||
next() {
|
next() {
|
||||||
this.player.playNextTrack(true);
|
this.player.playNextFMTrack().then(result => {
|
||||||
this.getColor();
|
if (result) {
|
||||||
|
this.getColor();
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
goToAlbum() {
|
goToAlbum() {
|
||||||
if (this.track.album.id === 0) return;
|
if (this.track.album.id === 0) return;
|
||||||
|
|
|
@ -87,9 +87,7 @@
|
||||||
>
|
>
|
||||||
<svg-icon :icon-class="player.playing ? 'pause' : 'play'"
|
<svg-icon :icon-class="player.playing ? 'pause' : 'play'"
|
||||||
/></button-icon>
|
/></button-icon>
|
||||||
<button-icon
|
<button-icon :title="$t('player.next')" @click.native="playNextTrack"
|
||||||
:title="$t('player.next')"
|
|
||||||
@click.native="player.playNextTrack"
|
|
||||||
><svg-icon icon-class="next"
|
><svg-icon icon-class="next"
|
||||||
/></button-icon>
|
/></button-icon>
|
||||||
</div>
|
</div>
|
||||||
|
@ -209,6 +207,13 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(['toggleLyrics']),
|
...mapMutations(['toggleLyrics']),
|
||||||
...mapActions(['showToast', 'likeATrack']),
|
...mapActions(['showToast', 'likeATrack']),
|
||||||
|
playNextTrack() {
|
||||||
|
if (this.player.isPersonalFM) {
|
||||||
|
this.player.playNextFMTrack();
|
||||||
|
} else {
|
||||||
|
this.player.playNextTrack();
|
||||||
|
}
|
||||||
|
},
|
||||||
goToNextTracksPage() {
|
goToNextTracksPage() {
|
||||||
if (this.player.isPersonalFM) return;
|
if (this.player.isPersonalFM) return;
|
||||||
this.$route.name === 'next'
|
this.$route.name === 'next'
|
||||||
|
|
|
@ -36,7 +36,11 @@ export function ipcRenderer(vueInstance) {
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('next', () => {
|
ipcRenderer.on('next', () => {
|
||||||
player.playNextTrack();
|
if (player.isPersonalFM) {
|
||||||
|
player.playNextFMTrack();
|
||||||
|
} else {
|
||||||
|
player.playNextTrack();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('previous', () => {
|
ipcRenderer.on('previous', () => {
|
||||||
|
|
|
@ -14,6 +14,11 @@ const electron =
|
||||||
process.env.IS_ELECTRON === true ? window.require('electron') : null;
|
process.env.IS_ELECTRON === true ? window.require('electron') : null;
|
||||||
const ipcRenderer =
|
const ipcRenderer =
|
||||||
process.env.IS_ELECTRON === true ? electron.ipcRenderer : null;
|
process.env.IS_ELECTRON === true ? electron.ipcRenderer : null;
|
||||||
|
const excludeSaveKeys = [
|
||||||
|
'_playing',
|
||||||
|
'_personalFMLoading',
|
||||||
|
'_personalFMNextLoading',
|
||||||
|
];
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -25,6 +30,8 @@ export default class {
|
||||||
this._shuffle = false; // true | false
|
this._shuffle = false; // true | false
|
||||||
this._volume = 1; // 0 to 1
|
this._volume = 1; // 0 to 1
|
||||||
this._volumeBeforeMuted = 1; // 用于保存静音前的音量
|
this._volumeBeforeMuted = 1; // 用于保存静音前的音量
|
||||||
|
this._personalFMLoading = false; // 是否正在私人FM中加载新的track
|
||||||
|
this._personalFMNextLoading = false; // 是否正在缓存私人FM的下一首歌曲
|
||||||
|
|
||||||
// 播放信息
|
// 播放信息
|
||||||
this._list = []; // 播放列表
|
this._list = []; // 播放列表
|
||||||
|
@ -162,7 +169,11 @@ export default class {
|
||||||
this._setIntervals();
|
this._setIntervals();
|
||||||
|
|
||||||
// 初始化私人FM
|
// 初始化私人FM
|
||||||
if (this._personalFMTrack.id === 0 || this._personalFMNextTrack.id === 0) {
|
if (
|
||||||
|
this._personalFMTrack.id === 0 ||
|
||||||
|
this._personalFMNextTrack.id === 0 ||
|
||||||
|
this._personalFMTrack.id === this._personalFMNextTrack.id
|
||||||
|
) {
|
||||||
personalFM().then(result => {
|
personalFM().then(result => {
|
||||||
this._personalFMTrack = result.data[0];
|
this._personalFMTrack = result.data[0];
|
||||||
this._personalFMNextTrack = result.data[1];
|
this._personalFMNextTrack = result.data[1];
|
||||||
|
@ -338,16 +349,22 @@ export default class {
|
||||||
return source;
|
return source;
|
||||||
} else {
|
} else {
|
||||||
store.dispatch('showToast', `无法播放 ${track.name}`);
|
store.dispatch('showToast', `无法播放 ${track.name}`);
|
||||||
ifUnplayableThen === 'playNextTrack'
|
if (ifUnplayableThen === 'playNextTrack') {
|
||||||
? this.playNextTrack()
|
if (this.isPersonalFM) {
|
||||||
: this.playPrevTrack();
|
this.playNextFMTrack();
|
||||||
|
} else {
|
||||||
|
this.playNextTrack();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.playPrevTrack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_cacheNextTrack() {
|
_cacheNextTrack() {
|
||||||
let nextTrackID = this._isPersonalFM
|
let nextTrackID = this._isPersonalFM
|
||||||
? this._personalFMNextTrack.id
|
? this._personalFMNextTrack?.id ?? 0
|
||||||
: this._getNextTrack()[0];
|
: this._getNextTrack()[0];
|
||||||
if (!nextTrackID) return;
|
if (!nextTrackID) return;
|
||||||
if (this._personalFMTrack.id == nextTrackID) return;
|
if (this._personalFMTrack.id == nextTrackID) return;
|
||||||
|
@ -375,7 +392,11 @@ export default class {
|
||||||
this.playPrevTrack();
|
this.playPrevTrack();
|
||||||
});
|
});
|
||||||
navigator.mediaSession.setActionHandler('nexttrack', () => {
|
navigator.mediaSession.setActionHandler('nexttrack', () => {
|
||||||
this.playNextTrack();
|
if (this.isPersonalFM) {
|
||||||
|
this.playNextFMTrack();
|
||||||
|
} else {
|
||||||
|
this.playNextTrack();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
navigator.mediaSession.setActionHandler('stop', () => {
|
navigator.mediaSession.setActionHandler('stop', () => {
|
||||||
this.pause();
|
this.pause();
|
||||||
|
@ -428,16 +449,33 @@ export default class {
|
||||||
this._scrobble(this._currentTrack, 0, true);
|
this._scrobble(this._currentTrack, 0, true);
|
||||||
if (!this.isPersonalFM && this.repeatMode === 'one') {
|
if (!this.isPersonalFM && this.repeatMode === 'one') {
|
||||||
this._replaceCurrentTrack(this._currentTrack.id);
|
this._replaceCurrentTrack(this._currentTrack.id);
|
||||||
|
} else if (this.isPersonalFM) {
|
||||||
|
this.playNextFMTrack();
|
||||||
} else {
|
} else {
|
||||||
this.playNextTrack();
|
this.playNextTrack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_loadPersonalFMNextTrack() {
|
_loadPersonalFMNextTrack() {
|
||||||
return personalFM().then(result => {
|
if (this._personalFMNextLoading) {
|
||||||
this._personalFMNextTrack = result.data[0];
|
return [false, undefined];
|
||||||
this._cacheNextTrack(); // cache next track
|
}
|
||||||
return this._personalFMNextTrack;
|
this._personalFMNextLoading = true;
|
||||||
});
|
return personalFM()
|
||||||
|
.then(result => {
|
||||||
|
if (!result || !result.data) {
|
||||||
|
this._personalFMNextTrack = undefined;
|
||||||
|
} else {
|
||||||
|
this._personalFMNextTrack = result.data[0];
|
||||||
|
this._cacheNextTrack(); // cache next track
|
||||||
|
}
|
||||||
|
this._personalFMNextLoading = false;
|
||||||
|
return [true, this._personalFMNextTrack];
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this._personalFMNextTrack = undefined;
|
||||||
|
this._personalFMNextLoading = false;
|
||||||
|
return [false, this._personalFMNextTrack];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_playDiscordPresence(track, seekTime = 0) {
|
_playDiscordPresence(track, seekTime = 0) {
|
||||||
if (
|
if (
|
||||||
|
@ -467,14 +505,7 @@ export default class {
|
||||||
appendTrack(trackID) {
|
appendTrack(trackID) {
|
||||||
this.list.append(trackID);
|
this.list.append(trackID);
|
||||||
}
|
}
|
||||||
playNextTrack(isFM = false) {
|
playNextTrack() {
|
||||||
if (this._isPersonalFM || isFM === true) {
|
|
||||||
this._isPersonalFM = true;
|
|
||||||
this._personalFMTrack = this._personalFMNextTrack;
|
|
||||||
this._replaceCurrentTrack(this._personalFMTrack.id);
|
|
||||||
this._loadPersonalFMNextTrack();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// TODO: 切换歌曲时增加加载中的状态
|
// TODO: 切换歌曲时增加加载中的状态
|
||||||
const [trackID, index] = this._getNextTrack();
|
const [trackID, index] = this._getNextTrack();
|
||||||
if (trackID === undefined) {
|
if (trackID === undefined) {
|
||||||
|
@ -486,6 +517,34 @@ export default class {
|
||||||
this._replaceCurrentTrack(trackID);
|
this._replaceCurrentTrack(trackID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
async playNextFMTrack() {
|
||||||
|
if (this._personalFMLoading) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._isPersonalFM = true;
|
||||||
|
if (!this._personalFMNextTrack) {
|
||||||
|
this._personalFMLoading = true;
|
||||||
|
let result = await personalFM().catch(() => null);
|
||||||
|
this._personalFMLoading = false;
|
||||||
|
if (!result || !result.data) {
|
||||||
|
store.dispatch('showToast', 'personal fm timeout');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 这里只能拿到一条数据
|
||||||
|
this._personalFMTrack = result.data[0];
|
||||||
|
} else {
|
||||||
|
if (this._personalFMNextTrack.id === this._personalFMTrack.id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this._personalFMTrack = this._personalFMNextTrack;
|
||||||
|
}
|
||||||
|
if (this._isPersonalFM) {
|
||||||
|
this._replaceCurrentTrack(this._personalFMTrack.id);
|
||||||
|
}
|
||||||
|
this._loadPersonalFMNextTrack();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
playPrevTrack() {
|
playPrevTrack() {
|
||||||
const [trackID, index] = this._getPrevTrack();
|
const [trackID, index] = this._getPrevTrack();
|
||||||
if (trackID === undefined) return false;
|
if (trackID === undefined) return false;
|
||||||
|
@ -496,7 +555,7 @@ export default class {
|
||||||
saveSelfToLocalStorage() {
|
saveSelfToLocalStorage() {
|
||||||
let player = {};
|
let player = {};
|
||||||
for (let [key, value] of Object.entries(this)) {
|
for (let [key, value] of Object.entries(this)) {
|
||||||
if (key === '_playing') continue;
|
if (excludeSaveKeys.includes(key)) continue;
|
||||||
player[key] = value;
|
player[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +679,13 @@ export default class {
|
||||||
}
|
}
|
||||||
addTrackToPlayNext(trackID, playNow = false) {
|
addTrackToPlayNext(trackID, playNow = false) {
|
||||||
this._playNextList.push(trackID);
|
this._playNextList.push(trackID);
|
||||||
if (playNow) this.playNextTrack();
|
if (playNow) {
|
||||||
|
if (this.isPersonalFM) {
|
||||||
|
this.playNextFMTrack();
|
||||||
|
} else {
|
||||||
|
this.playNextTrack();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
playPersonalFM() {
|
playPersonalFM() {
|
||||||
this._isPersonalFM = true;
|
this._isPersonalFM = true;
|
||||||
|
@ -633,10 +698,12 @@ export default class {
|
||||||
this.playOrPause();
|
this.playOrPause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moveToFMTrash() {
|
async moveToFMTrash() {
|
||||||
this._isPersonalFM = true;
|
this._isPersonalFM = true;
|
||||||
this.playNextTrack();
|
let id = this._personalFMTrack.id;
|
||||||
fmTrash(this._personalFMTrack.id);
|
if (await this.playNextFMTrack()) {
|
||||||
|
fmTrash(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendSelfToIpcMain() {
|
sendSelfToIpcMain() {
|
||||||
|
|
|
@ -151,7 +151,7 @@
|
||||||
</button-icon>
|
</button-icon>
|
||||||
<button-icon
|
<button-icon
|
||||||
:title="$t('player.next')"
|
:title="$t('player.next')"
|
||||||
@click.native="player.playNextTrack"
|
@click.native="playNextTrack"
|
||||||
>
|
>
|
||||||
<svg-icon icon-class="next" />
|
<svg-icon icon-class="next" />
|
||||||
</button-icon>
|
</button-icon>
|
||||||
|
@ -318,6 +318,13 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(['toggleLyrics']),
|
...mapMutations(['toggleLyrics']),
|
||||||
...mapActions(['likeATrack']),
|
...mapActions(['likeATrack']),
|
||||||
|
playNextTrack() {
|
||||||
|
if (this.player.isPersonalFM) {
|
||||||
|
this.player.playNextFMTrack();
|
||||||
|
} else {
|
||||||
|
this.player.playNextTrack();
|
||||||
|
}
|
||||||
|
},
|
||||||
getLyric() {
|
getLyric() {
|
||||||
if (!this.currentTrack.id) return;
|
if (!this.currentTrack.id) return;
|
||||||
return getLyric(this.currentTrack.id).then(data => {
|
return getLyric(this.currentTrack.id).then(data => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user