mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 05:08:04 +00:00
refactor: 将 player.ts 里面的Mode.PLAYLIST改为 Mode.TrackList
This commit is contained in:
parent
7b6579e068
commit
0061a66124
6 changed files with 22 additions and 12 deletions
|
|
@ -102,7 +102,7 @@ const Controls = () => {
|
|||
|
||||
return (
|
||||
<div className='flex items-center justify-center gap-2 text-white'>
|
||||
{mode === PlayerMode.PLAYLIST && (
|
||||
{mode === PlayerMode.TrackList && (
|
||||
<IconButton
|
||||
onClick={() => track && player.prevTrack()}
|
||||
disabled={!track}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ const MediaControls = () => {
|
|||
|
||||
return (
|
||||
<div className='flex items-center justify-center gap-2 text-black dark:text-white'>
|
||||
{mode === PlayerMode.PLAYLIST && (
|
||||
{mode === PlayerMode.TrackList && (
|
||||
<IconButton
|
||||
onClick={() => track && player.prevTrack()}
|
||||
disabled={!track}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ const Playlists = () => {
|
|||
>
|
||||
<span className='line-clamp-1'>{playlist.name}</span>
|
||||
{playlistMode === TrackListSourceType.PLAYLIST &&
|
||||
mode === Mode.PLAYLIST &&
|
||||
mode === Mode.TrackList &&
|
||||
currentPlaylistID === playlist.id && (
|
||||
<SvgIcon className='h-5 w-5' name='volume-half' />
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -37,10 +37,15 @@ const PlayButton = ({
|
|||
const playerSnapshot = useSnapshot(player)
|
||||
const isThisAlbumPlaying = useMemo(
|
||||
() =>
|
||||
playerSnapshot.mode === PlayerMode.PLAYLIST &&
|
||||
playerSnapshot.mode === PlayerMode.TrackList &&
|
||||
playerSnapshot.trackListSource?.type === TrackListSourceType.ALBUM &&
|
||||
playerSnapshot.trackListSource?.id === album?.id,
|
||||
[playerSnapshot.trackListSource, album?.id]
|
||||
[
|
||||
playerSnapshot.mode,
|
||||
playerSnapshot.trackListSource?.type,
|
||||
playerSnapshot.trackListSource?.id,
|
||||
album?.id,
|
||||
]
|
||||
)
|
||||
|
||||
const isPlaying =
|
||||
|
|
|
|||
|
|
@ -32,10 +32,15 @@ const PlayButton = ({
|
|||
const playerSnapshot = useSnapshot(player)
|
||||
const isThisPlaylistPlaying = useMemo(
|
||||
() =>
|
||||
playerSnapshot.mode === PlayerMode.PLAYLIST &&
|
||||
playerSnapshot.mode === PlayerMode.TrackList &&
|
||||
playerSnapshot.trackListSource?.type === TrackListSourceType.PLAYLIST &&
|
||||
playerSnapshot.trackListSource?.id === playlist?.id,
|
||||
[playerSnapshot.trackListSource, playlist?.id]
|
||||
[
|
||||
playerSnapshot.mode,
|
||||
playerSnapshot.trackListSource?.id,
|
||||
playerSnapshot.trackListSource?.type,
|
||||
playlist?.id,
|
||||
]
|
||||
)
|
||||
|
||||
const wrappedHandlePlay = () => {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ interface TrackListSource {
|
|||
id: number
|
||||
}
|
||||
export enum Mode {
|
||||
PLAYLIST = 'playlist',
|
||||
TrackList = 'trackList',
|
||||
FM = 'fm',
|
||||
}
|
||||
export enum State {
|
||||
|
|
@ -49,7 +49,7 @@ export class Player {
|
|||
private _volume: number = 1 // 0 to 1
|
||||
|
||||
state: State = State.INITIALIZING
|
||||
mode: Mode = Mode.PLAYLIST
|
||||
mode: Mode = Mode.TrackList
|
||||
trackList: TrackID[] = []
|
||||
trackListSource: TrackListSource | null = null
|
||||
fmTrackList: TrackID[] = []
|
||||
|
|
@ -115,7 +115,7 @@ export class Player {
|
|||
* Get current playing track ID
|
||||
*/
|
||||
get trackID(): TrackID {
|
||||
if (this.mode === Mode.PLAYLIST) {
|
||||
if (this.mode === Mode.TrackList) {
|
||||
const { trackList, _trackIndex } = this
|
||||
return trackList[_trackIndex] ?? 0
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ export class Player {
|
|||
toast('加载歌曲信息失败')
|
||||
return
|
||||
}
|
||||
if (this.mode === Mode.PLAYLIST) this._track = track
|
||||
if (this.mode === Mode.TrackList) this._track = track
|
||||
if (this.mode === Mode.FM) this.fmTrack = track
|
||||
this._playAudio()
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ export class Player {
|
|||
* @param {null|number} autoPlayTrackID
|
||||
*/
|
||||
playAList(list: TrackID[], autoPlayTrackID?: null | number) {
|
||||
this.mode = Mode.PLAYLIST
|
||||
this.mode = Mode.TrackList
|
||||
this.trackList = list
|
||||
this._trackIndex = autoPlayTrackID
|
||||
? list.findIndex(t => t === autoPlayTrackID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue