Skip to content

Commit

Permalink
remove the play statu from the player state
Browse files Browse the repository at this point in the history
  • Loading branch information
nini22P committed Jan 5, 2025
1 parent 1a9da1e commit f9ae2e8
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/components/CommonList/CommonList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const CommonList = (
const updatePlayQueue = usePlayQueueStore.use.updatePlayQueue()
const updateCurrentIndex = usePlayQueueStore.use.updateCurrentIndex()

const updatePlayStatu = usePlayerStore((state) => state.updatePlayStatu)
const updateAutoPlay = usePlayerStore((state) => state.updateAutoPlay)

const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null)
const [menuOpen, setMenuOpen] = useState(false)
Expand Down Expand Up @@ -85,7 +85,7 @@ const CommonList = (
const shuffleList = shufflePlayQueue(list) || []
updatePlayQueue(shuffleList)
updateCurrentIndex(shuffleList[0].index)
updatePlayStatu('playing')
updateAutoPlay(true)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/hooks/player/usePlayerControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const usePlayerControl = (player: HTMLVideoElement | null) => {
const updatePlayQueue = usePlayQueueStore.use.updatePlayQueue()

const [
updatePlayStatu,
updateAutoPlay,
updateCurrentTime,
] = usePlayerStore(
useShallow(
(state) => [
state.updatePlayStatu,
state.updateAutoPlay,
state.updateCurrentTime,
]
)
Expand Down Expand Up @@ -46,13 +46,13 @@ const usePlayerControl = (player: HTMLVideoElement | null) => {

// 播放开始
const handleClickPlay = () => {
updatePlayStatu('playing')
updateAutoPlay(true)
player?.play()
}

// 播放暂停
const handleClickPause = () => {
updatePlayStatu('paused')
updateAutoPlay(false)
player?.pause()
}

Expand Down
41 changes: 13 additions & 28 deletions src/hooks/player/usePlayerCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const usePlayerCore = (player: HTMLVideoElement | null) => {
const [
currentMetaData,
metadataUpdate,
playStatu,
autoPlay,
isLoading,
updateCurrentMetaData,
updateMetadataUpdate,
updatePlayStatu,
updateAutoPlay,
updateIsLoading,
updateCover,
updateCurrentTime,
Expand All @@ -33,11 +33,11 @@ const usePlayerCore = (player: HTMLVideoElement | null) => {
(state) => [
state.currentMetaData,
state.metadataUpdate,
state.playStatu,
state.autoPlay,
state.isLoading,
state.updateCurrentMetaData,
state.updateMetadataUpdate,
state.updatePlayStatu,
state.updateAutoPlay,
state.updateIsLoading,
state.updateCover,
state.updateCurrentTime,
Expand Down Expand Up @@ -77,7 +77,7 @@ const usePlayerCore = (player: HTMLVideoElement | null) => {
})
} catch (error) {
console.error(error)
updatePlayStatu('paused')
updateAutoPlay(false)
updateIsLoading(false)
player?.pause()
}
Expand All @@ -94,27 +94,9 @@ const usePlayerCore = (player: HTMLVideoElement | null) => {
updateDuration(0)
player.load()
player.onloadedmetadata = () => {
if (isLoading && playStatu === 'playing') {
if (isLoading && autoPlay) {
player.play()
}
updateIsLoading(false)
updateDuration(player.duration)
}
}
return true
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[url]
)

// 插入播放历史
useEffect(
() => {
if (player !== null && !isLoading && player.src.includes('1drv.com') && currentFile) {
if (playStatu === 'playing') {
console.log('Playing', currentFile.filePath)
if (currentFile.filePath) {
if (historyList !== null) {
if (historyList && currentFile) {
insertHistory({
fileName: currentFile.fileName,
filePath: currentFile.filePath,
Expand All @@ -123,11 +105,14 @@ const usePlayerCore = (player: HTMLVideoElement | null) => {
})
}
}
updateIsLoading(false)
updateDuration(player.duration)
}
}
return true
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[currentFile, playStatu]
[url]
)

// 设置当前播放进度
Expand All @@ -150,9 +135,9 @@ const usePlayerCore = (player: HTMLVideoElement | null) => {
player?.play()
} else if (repeat === 'off' || repeat === 'all') {
if (isPlayQueueEnd || !next) {
if (repeat === 'off'){
updatePlayStatu('paused')
if (repeat === 'off') {
player?.pause()
updateAutoPlay(false)
}
updateCurrentIndex(playQueue[0].index)
} else
Expand Down
22 changes: 11 additions & 11 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ msgid "Clear"
msgstr "Clear"

#: src/pages/PictureView/PictureView.tsx:72
#: src/pages/Player/Audio/Modern.tsx:154
#: src/pages/Player/Audio/Modern.tsx:152
#: src/pages/Player/VideoPlayerTopbar.tsx:56
msgid "Close"
msgstr "Close"
Expand All @@ -88,6 +88,10 @@ msgstr "Color mode"
msgid "Current"
msgstr "Current"

#: src/pages/NavBar.tsx:122
msgid "Currently using a development version, please be careful with your data!"
msgstr "Currently using a development version, please be careful with your data!"

#: src/pages/Setting.tsx:127
msgid "Customize"
msgstr "Customize"
Expand Down Expand Up @@ -120,8 +124,8 @@ msgstr "Files"
msgid "Folders first"
msgstr "Folders first"

#: src/pages/Player/Audio/Modern.tsx:204
#: src/pages/Player/PlayerControl.tsx:318
#: src/pages/Player/Audio/Modern.tsx:202
#: src/pages/Player/PlayerControl.tsx:316
msgid "Fullscreen"
msgstr "Fullscreen"

Expand Down Expand Up @@ -157,7 +161,7 @@ msgstr "List"
msgid "Local metaData cache"
msgstr "Local metaData cache"

#: src/pages/Player/Audio/Modern.tsx:187
#: src/pages/Player/Audio/Modern.tsx:185
msgid "Lyrics"
msgstr "Lyrics"

Expand Down Expand Up @@ -198,7 +202,7 @@ msgid "New playlist"
msgstr "New playlist"

#: src/components/Lyrics/Lyrics.tsx:87
#: src/pages/Player/Audio/Modern.tsx:285
#: src/pages/Player/Audio/Modern.tsx:283
msgid "No lyrics"
msgstr "No lyrics"

Expand All @@ -220,8 +224,8 @@ msgstr "Open source dependencies"
msgid "Play all"
msgstr "Play all"

#: src/pages/Player/Audio/Modern.tsx:172
#: src/pages/Player/PlayerControl.tsx:308
#: src/pages/Player/Audio/Modern.tsx:170
#: src/pages/Player/PlayerControl.tsx:306
#: src/pages/Player/PlayerMenu.tsx:221
msgid "Play queue"
msgstr "Play queue"
Expand Down Expand Up @@ -297,10 +301,6 @@ msgstr "Switch fullscreen"
msgid "Switch theme"
msgstr "Switch theme"

#: src/pages/NavBar.tsx:122
msgid "The current version in use is a development version. Please be cautious about data security!"
msgstr "The current version in use is a development version. Please be cautious about data security!"

#: src/pages/Playlist/Playlist.tsx:237
msgid "The playlist will be deleted"
msgstr "The playlist will be deleted"
Expand Down
22 changes: 11 additions & 11 deletions src/locales/zh-CN/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ msgid "Clear"
msgstr "清除"

#: src/pages/PictureView/PictureView.tsx:72
#: src/pages/Player/Audio/Modern.tsx:154
#: src/pages/Player/Audio/Modern.tsx:152
#: src/pages/Player/VideoPlayerTopbar.tsx:56
msgid "Close"
msgstr "关闭"
Expand All @@ -88,6 +88,10 @@ msgstr "颜色模式"
msgid "Current"
msgstr "当前"

#: src/pages/NavBar.tsx:122
msgid "Currently using a development version, please be careful with your data!"
msgstr "当前正在使用开发版本,请注意数据安全!"

#: src/pages/Setting.tsx:127
msgid "Customize"
msgstr "定制"
Expand Down Expand Up @@ -120,8 +124,8 @@ msgstr "文件"
msgid "Folders first"
msgstr "文件夹优先"

#: src/pages/Player/Audio/Modern.tsx:204
#: src/pages/Player/PlayerControl.tsx:318
#: src/pages/Player/Audio/Modern.tsx:202
#: src/pages/Player/PlayerControl.tsx:316
msgid "Fullscreen"
msgstr "全屏"

Expand Down Expand Up @@ -157,7 +161,7 @@ msgstr "列表"
msgid "Local metaData cache"
msgstr "本地元数据缓存"

#: src/pages/Player/Audio/Modern.tsx:187
#: src/pages/Player/Audio/Modern.tsx:185
msgid "Lyrics"
msgstr "歌词"

Expand Down Expand Up @@ -198,7 +202,7 @@ msgid "New playlist"
msgstr "新播放列表"

#: src/components/Lyrics/Lyrics.tsx:87
#: src/pages/Player/Audio/Modern.tsx:285
#: src/pages/Player/Audio/Modern.tsx:283
msgid "No lyrics"
msgstr "无歌词"

Expand All @@ -220,8 +224,8 @@ msgstr "开源库"
msgid "Play all"
msgstr "全部播放"

#: src/pages/Player/Audio/Modern.tsx:172
#: src/pages/Player/PlayerControl.tsx:308
#: src/pages/Player/Audio/Modern.tsx:170
#: src/pages/Player/PlayerControl.tsx:306
#: src/pages/Player/PlayerMenu.tsx:221
msgid "Play queue"
msgstr "播放队列"
Expand Down Expand Up @@ -297,10 +301,6 @@ msgstr "切换全屏"
msgid "Switch theme"
msgstr "切换主题"

#: src/pages/NavBar.tsx:122
msgid "The current version in use is a development version. Please be cautious about data security!"
msgstr "当前正在使用开发版本,请注意保护数据安全!"

#: src/pages/Playlist/Playlist.tsx:237
msgid "The playlist will be deleted"
msgstr "播放列表将会被删除"
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Files/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Files = () => {
const updatePlayQueue = usePlayQueueStore.use.updatePlayQueue()
const updateCurrentIndex = usePlayQueueStore.use.updateCurrentIndex()

const updatePlayStatu = usePlayerStore(state => state.updatePlayStatu)
const updateAutoPlay = usePlayerStore(state => state.updateAutoPlay)

const { getFilesData } = useFilesData()
const navigate = useNavigate()
Expand Down Expand Up @@ -143,7 +143,7 @@ const Files = () => {
}
updatePlayQueue(list)
updateCurrentIndex(list.find(item => pathConvert(item.filePath) === pathConvert(currentFile.filePath))?.index || 0)
updatePlayStatu('playing')
updateAutoPlay(true)
if (currentFile.fileType === 'video') {
updateVideoViewIsShow(true)
}
Expand All @@ -165,7 +165,7 @@ const Files = () => {
}
updatePlayQueue(list)
updateCurrentIndex(0)
updatePlayStatu('playing')
updateAutoPlay(true)
if (list[0].fileType === 'video') {
updateVideoViewIsShow(true)
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const History = () => {
const updatePlayQueue = usePlayQueueStore.use.updatePlayQueue()
const updateCurrentIndex = usePlayQueueStore.use.updateCurrentIndex()

const updatePlayStatu = usePlayerStore(state => state.updatePlayStatu)
const updateAutoPlay = usePlayerStore(state => state.updateAutoPlay)

const open = (index: number) => {
const listData = historyList
Expand All @@ -32,7 +32,7 @@ const History = () => {
}
updatePlayQueue(list)
updateCurrentIndex(list[index].index)
updatePlayStatu('playing')
updateAutoPlay(true)
if (checkFileType(currentFile.fileName) === 'video') {
updateVideoViewIsShow(true)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const NavBar = () => {
OMP
{
INFO.dev &&
<Tooltip title={t`The current version in use is a development version. Please be cautious about data security!`}>
<Tooltip title={t`Currently using a development version, please be careful with your data!`}>
<span
style={{
marginLeft: '0.25rem',
Expand Down
6 changes: 2 additions & 4 deletions src/pages/Player/Audio/Classic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const Classic = ({ player, styles }: { player: HTMLVideoElement | null, styles:

const [
currentMetaData,
playStatu,
isLoading,
cover,
currentTime,
Expand All @@ -52,7 +51,6 @@ const Classic = ({ player, styles }: { player: HTMLVideoElement | null, styles:
useShallow(
(state) => [
state.currentMetaData,
state.playStatu,
state.isLoading,
state.cover,
state.currentTime,
Expand Down Expand Up @@ -227,13 +225,13 @@ const Classic = ({ player, styles }: { player: HTMLVideoElement | null, styles:
<FastRewind sx={{ height: 32, width: 32 }} />
</IconButton>
{
(!isLoading && playStatu === 'paused') &&
(!isLoading && player?.paused) &&
<IconButton aria-label="play" onClick={() => handleClickPlay()}>
<PlayCircleOutlined sx={{ height: 64, width: 64 }} />
</IconButton>
}
{
(!isLoading && playStatu === 'playing') &&
(!isLoading && !player?.paused) &&
<IconButton aria-label="pause" onClick={() => handleClickPause()}>
<PauseCircleOutlined sx={{ height: 64, width: 64 }} />
</IconButton>
Expand Down
Loading

0 comments on commit f9ae2e8

Please sign in to comment.