Unify playback-state read/write via /api/meta/playback-state

This commit is contained in:
2026-05-31 01:43:56 +00:00
parent b6742f0f27
commit 626fb9a0ae
6 changed files with 435 additions and 83 deletions
+3 -5
View File
@@ -207,7 +207,6 @@ import {
openFolder,
isMpcBeReachable,
fetchResumePositions,
normalizeMediaPath,
getPlayerStatus,
} from "./api"
import { useSettings } from "./composables/useSettings"
@@ -547,10 +546,9 @@ async function refreshPlayerStatus() {
}
}
function hasResumePosition(filePath: string | null) {
if (!filePath) return false
const normalizedPath = normalizeMediaPath(filePath)
return Number(resumePositions.value[normalizedPath] || 0) > 0
function hasResumePosition(mediaId: string | null) {
if (!mediaId) return false
return Number(resumePositions.value[mediaId] || 0) > 0
}
function startMpcBePolling() {
+9 -1
View File
@@ -126,7 +126,15 @@ export async function fetchResumePositions(): Promise<Record<string, number>> {
if (!positions || typeof positions !== "object") {
return {}
}
return positions as Record<string, number>
const normalized: Record<string, number> = {}
for (const [slug, value] of Object.entries(positions as Record<string, unknown>)) {
if (!value || typeof value !== "object") continue
const pos = (value as { pos?: unknown }).pos
if (typeof pos === "number" && Number.isFinite(pos) && pos > 0) {
normalized[slug] = pos
}
}
return normalized
} catch {
return {}
}
+3 -2
View File
@@ -256,7 +256,7 @@ const props = defineProps<{
item: MediaItem
allMovies: MovieUi[]
focusEpisode?: { seasonNumber: number; episodeNumber: number } | null
hasResumePosition: (filePath: string | null) => boolean
hasResumePosition: (mediaId: string | null) => boolean
getRootName: (rootId: string | null | undefined) => string | null
}>()
const emit = defineEmits<{
@@ -828,7 +828,8 @@ function closeVersionActionMenu() {
}
function getPlayLabel(filePath: string | null): string {
return props.hasResumePosition(filePath) ? "Continue" : "Play"
if (!filePath || props.item.type !== "movies") return "Play"
return props.hasResumePosition(props.item.id) ? "Continue" : "Play"
}
function handlePlayVersion(filePath: string | null) {