Skip to content

Commit

Permalink
fix: should reset timer (#156)
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei authored Jul 26, 2024
1 parent 4188142 commit e11b162
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/renderer/src/atoms/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ export const [
setPlayerAtomValue,
usePlayerAtomSelector,
] = createAtomHooks<PlayerAtomValue>(
atomWithStorage(
getStorageNS("player"),
playerInitialValue,
undefined,
{ getOnInit: true },
),
atomWithStorage(getStorageNS("player"), playerInitialValue, undefined, {
getOnInit: true,
}),
)

export const Player = {
Expand All @@ -45,7 +42,9 @@ export const Player = {
get() {
return getPlayerAtomValue()
},
play(v: Omit<PlayerAtomValue, "show" | "status" | "playedSeconds" | "duration">) {
play(
v: Omit<PlayerAtomValue, "show" | "status" | "playedSeconds" | "duration">,
) {
const curV = getPlayerAtomValue()
if (!v.src || (curV.src === v.src && curV.status === "playing")) {
return
Expand Down Expand Up @@ -81,6 +80,10 @@ export const Player = {
})
})
},
teardown() {
this.currentTimeTimer && clearInterval(this.currentTimeTimer)
this.audio.pause()
},
pause() {
const curV = getPlayerAtomValue()
if (curV.status === "paused") {
Expand All @@ -92,8 +95,8 @@ export const Player = {
status: "paused",
currentTime: this.audio.currentTime,
})

return this.audio.pause()
this.teardown()
return
},
togglePlayAndPause() {
const curV = getPlayerAtomValue()
Expand All @@ -112,9 +115,7 @@ export const Player = {
status: "paused",
})

this.currentTimeTimer && clearInterval(this.currentTimeTimer)

return this.audio.pause()
this.teardown()
},
seek(time: number) {
this.audio.currentTime = time
Expand Down

0 comments on commit e11b162

Please sign in to comment.