Skip to content

Commit

Permalink
fix(player): null and error states
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyadev committed Aug 6, 2024
1 parent c728de1 commit 2785b96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/components/app/providers/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ContextRichAudio({
// biome-ignore lint/style/noNonNullAssertion :
const { setMaxPosition, reactPosition } = usePosition()!
// biome-ignore lint/style/noNonNullAssertion :
const { trackComplete } = useQueue()!
const { trackComplete, nextTrack } = useQueue()!
return (
// biome-ignore lint/a11y/useMediaCaption :
<audio
Expand All @@ -30,18 +30,29 @@ function ContextRichAudio({
trackComplete()
}}
className="hidden"
onError={() => {
if (!audioRef.current) return
if (audioRef.current.src === "") return
nextTrack()
}}
/>
)
}

function ContextRichOverlay() {
// biome-ignore lint/style/noNonNullAssertion :
const { track } = useTrack()!


if (track === null) {
return null
}

return (
<div
className="z-10000 pointer-events-none fixed left-0 top-0 h-full w-full overflow-hidden bg-cover bg-center bg-no-repeat opacity-10 blur-xl"
style={{
backgroundImage: `url('/api/covers/?id=${track?.id}&size=xl')`,
backgroundImage: `url('/api/covers/?id=${track.id}&size=xl')`,
}}
/>
)
Expand Down
5 changes: 4 additions & 1 deletion src/components/app/providers/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const QueueProvider: React.FC<{
const { loop } = useLoop()!

const nextTrack = () => {
if (queue.length === 0) return
if (queue.length === 0) {
changeTrack(null, false)
return
}
const nextTrack = queue.shift()
if (nextTrack) {
setQueuePlayed([...queuePlayed, track])
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/providers/track.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const TrackProvider: React.FC<{
playing.setPlayingFalse()
position.changePosition([0])
if (!audioRef.current) return
audioRef.current.src = `/api/track_data?id=${newTrack?.id}`
audioRef.current.src = newTrack ? `/api/track_data?id=${newTrack?.id}` : ''
localStorage.setItem('track', JSON.stringify(newTrack))

if (play) {
Expand Down

0 comments on commit 2785b96

Please sign in to comment.