Skip to content

Commit 8bd75c3

Browse files
committed
Fix cover art
1 parent c6905af commit 8bd75c3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Build/src/components/Home.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ export const Home: React.FC<HomeProps> = ({ musicPlayerHook, onAddMusic }) => {
190190
);
191191

192192
const heroSong = playerState.currentSong || recentlyAdded[0] || null;
193+
194+
// Load album art for hero song if it's not the current song (which already has loaded album art)
195+
const heroSongAlbumArt = useAlbumArt(
196+
heroSong?.id,
197+
heroSong?.hasAlbumArt && !heroSong?.albumArt,
198+
);
193199
const hasLibraryContent = library.songs.length > 0;
194200

195201
const stats = [
@@ -246,9 +252,9 @@ export const Home: React.FC<HomeProps> = ({ musicPlayerHook, onAddMusic }) => {
246252
<div className={styles.home}>
247253
<section className={`${styles.panel} ${styles.hero}`}>
248254
<div className={styles.heroArt}>
249-
{heroSong?.albumArt ? (
255+
{heroSong?.albumArt || heroSongAlbumArt ? (
250256
<img
251-
src={heroSong.albumArt}
257+
src={heroSong?.albumArt || heroSongAlbumArt}
252258
alt={t("player.albumArtAlt", { title: heroSong.title })}
253259
/>
254260
) : (

Build/src/hooks/musicPlayerHook.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,27 @@ export const useMusicPlayer = () => {
800800
? { ...song, url: `indexeddb://${song.id}` }
801801
: song;
802802

803-
// Cache the song
803+
// Cache song
804804
await cacheSong(songToPlay);
805805
const cachedSong = getCachedSong(song.id);
806806
if (!cachedSong) {
807807
console.error("Failed to play song: could not cache");
808808
return;
809809
}
810810

811+
// Load album art for current song if it exists
812+
let songWithArt = song;
813+
if (song.hasAlbumArt && !song.albumArt) {
814+
try {
815+
const albumArt = await musicIndexedDbHelper.loadAlbumArt(song.id);
816+
if (albumArt) {
817+
songWithArt = { ...song, albumArt };
818+
}
819+
} catch (error) {
820+
console.warn("Failed to load album art for current song:", error);
821+
}
822+
}
823+
811824
// Prepare playlist
812825
const preparedPlaylist =
813826
playlist && "songs" in playlist
@@ -816,7 +829,7 @@ export const useMusicPlayer = () => {
816829

817830
setPlayerState((prev) => ({
818831
...prev,
819-
currentSong: song,
832+
currentSong: songWithArt,
820833
currentPlaylist: preparedPlaylist,
821834
isPlaying: true,
822835
currentTime: 0,

0 commit comments

Comments
 (0)