Compare commits
1
Commits
No files matched your search
@@ -376,7 +376,8 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
const handlePlaylistStatusUpdate = useCallback(
|
||||
(status: AudioPlaylistStatus) => {
|
||||
if (!status.isLoaded) return
|
||||
// iOS may remove the finished item before delivering its final status.
|
||||
if (!status.isLoaded && !status.didJustFinish) return
|
||||
const state = storeRef.current.getState()
|
||||
if (loadedSongIdsRef.current[status.currentIndex] !== state.queue[0]) {
|
||||
return
|
||||
@@ -427,7 +428,14 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
isPlayingRef.current = false
|
||||
setIsPlayingState(false)
|
||||
storeRef.current.update(playbackQueue.skipNext)
|
||||
void playlistRef.current?.seekTo(0)
|
||||
const playlist = playlistRef.current
|
||||
if (playlist) {
|
||||
playlist.pause()
|
||||
// Reload the final item, which iOS removes when playback ends.
|
||||
ignoreTrackChangeRef.current = true
|
||||
playlist.skipTo(status.currentIndex)
|
||||
scheduleTrackChangeHandling()
|
||||
}
|
||||
currentTimeRef.current = 0
|
||||
setCurrentTime(0)
|
||||
return
|
||||
@@ -443,7 +451,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
playlist?.play()
|
||||
}
|
||||
},
|
||||
[]
|
||||
[scheduleTrackChangeHandling]
|
||||
)
|
||||
|
||||
const handleTrackChanged = useCallback(
|
||||
|
||||
@@ -955,6 +955,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
if (!shouldContinuePlaying) {
|
||||
autoPlayNextRef.current = false
|
||||
isPlayingRef.current = false
|
||||
audio.pause()
|
||||
audio.currentTime = 0
|
||||
currentTimeRef.current = 0
|
||||
setCurrentTime(0)
|
||||
|
||||
@@ -68,21 +68,6 @@ async function coverPathIfExists(path: string): Promise<string | null> {
|
||||
.catch(() => null)
|
||||
}
|
||||
|
||||
async function shouldReplaceCover(dbCover: string | null) {
|
||||
return dbCover === null || (await coverPathIfExists(dbCover)) === null
|
||||
}
|
||||
|
||||
function isCodecPath(filePath: string, codec: string) {
|
||||
return filePath.startsWith(`${DATA_DIR}/${codec}/`)
|
||||
}
|
||||
|
||||
function releaseDate(common: music.ICommonTagsResult) {
|
||||
if (common.date) {
|
||||
return common.date
|
||||
}
|
||||
return common.year ? `01-01-${common.year}` : ""
|
||||
}
|
||||
|
||||
async function syncArtistCover(
|
||||
ctx: ActionCtx,
|
||||
codec: string,
|
||||
@@ -92,13 +77,13 @@ async function syncArtistCover(
|
||||
) {
|
||||
const onDisk = await coverPathIfExists(diskPath)
|
||||
if (onDisk !== null) {
|
||||
if (await shouldReplaceCover(dbCover)) {
|
||||
if (dbCover !== onDisk) {
|
||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||
id,
|
||||
cover: onDisk,
|
||||
})
|
||||
}
|
||||
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||
id,
|
||||
cover: null,
|
||||
@@ -115,13 +100,13 @@ async function syncAlbumCover(
|
||||
) {
|
||||
const onDisk = await coverPathIfExists(diskPath)
|
||||
if (onDisk !== null) {
|
||||
if (await shouldReplaceCover(dbCover)) {
|
||||
if (dbCover !== onDisk) {
|
||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||
id,
|
||||
cover: onDisk,
|
||||
})
|
||||
}
|
||||
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||
id,
|
||||
cover: null,
|
||||
@@ -417,8 +402,9 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
name: metadata.common.album || potentialAlbum,
|
||||
folder: potentialAlbum,
|
||||
cover,
|
||||
year: metadata.common.year || 0,
|
||||
date: releaseDate(metadata.common),
|
||||
year: metadata.common.year || 2026,
|
||||
date:
|
||||
metadata.common.date || `01-01-${metadata.common.year || 2026}`,
|
||||
artist: dbArtist._id,
|
||||
})
|
||||
} catch {}
|
||||
@@ -508,14 +494,11 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
)
|
||||
|
||||
if (existingSong) {
|
||||
// A tracked path that still exists is a different file with the
|
||||
// same title; replacing it would flip-flop between scans.
|
||||
const trackedPath = existingSong.files[codec]
|
||||
if (
|
||||
trackedPath === undefined ||
|
||||
!fsSync.existsSync(trackedPath)
|
||||
!(codec in existingSong.files) ||
|
||||
existingSong.files[codec] !== path
|
||||
) {
|
||||
const update = { ...existingSong.files, [codec]: path }
|
||||
const update = { [codec]: path, ...existingSong.files }
|
||||
updateSongs.push({
|
||||
id: existingSong._id,
|
||||
files: update,
|
||||
@@ -567,8 +550,10 @@ export const scheduledUpdateLibrary = internalAction({
|
||||
? null
|
||||
: metadata.common.disk.no,
|
||||
track: metadata.common.track.no || 0,
|
||||
year: metadata.common.year || 0,
|
||||
date: releaseDate(metadata.common),
|
||||
year: metadata.common.year || 2026,
|
||||
date:
|
||||
metadata.common.date ||
|
||||
`01-01-${metadata.common.year || 2026}`,
|
||||
genres: metadata.common.genre || [],
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user