feat: updates (#1462)

* fix: IconButton disable

* feat(components/Player): heart图标跟随用户喜欢的歌曲变化

* fix(pages/Artist): 对最新发行和EP判断是否存在数据

* fix(utils/player): 音频加载完成后检查id

避免切歌太快,导致已经被切歌音频覆盖当前音频

* update

* fix(utils/player): update

* fix(components/Player): 删掉多余的!!

* _initFM() private

* Update player.ts

Co-authored-by: qier222 <qier222@outlook.com>
This commit is contained in:
memorydream 2022-04-02 23:26:33 +08:00 committed by GitHub
parent 744247143b
commit f5ab5ea754
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 30 deletions

View file

@ -59,7 +59,7 @@ export class Player {
init() {
this.state = State.READY
this.initFM()
this._initFM()
}
/**
@ -134,6 +134,15 @@ export class Player {
Howler.volume(this._volume)
}
private async _initFM() {
const response = await fetchPersonalFMWithReactQuery()
this.fmTrackList.push(...(response?.data?.map(r => r.id) ?? []))
const trackId = this.fmTrackList[0]
const track = await this._fetchTrack(trackId)
if (track) this.fmTrack = track
}
private _setupProgressInterval() {
this._progressInterval = setInterval(() => {
if (this.state === State.PLAYING) this._progress = _howler.seek()
@ -145,9 +154,7 @@ export class Player {
*/
private async _fetchTrack(trackID: TrackID) {
const response = await fetchTracksWithReactQuery({ ids: [trackID] })
if (response.songs.length) {
return response.songs[0]
}
return response?.songs?.length ? response.songs[0] : null
}
/**
@ -187,6 +194,7 @@ export class Player {
toast('无法播放此歌曲')
return
}
if (this.trackID !== id) return
Howler.unload()
const howler = new Howl({
src: [`${audio}?id=${id}`],
@ -393,18 +401,6 @@ export class Player {
}
}
/**
* Init personal fm
*/
async initFM() {
const response = await fetchPersonalFMWithReactQuery()
this.fmTrackList.push(...(response?.data?.map(r => r.id) ?? []))
const trackId = this.fmTrackList[0]
const track = await this._fetchTrack(trackId)
if (track) this.fmTrack = track
}
/**
* Trash current PersonalFMTrack
*/