mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
Improve soundtrack player artwork
This commit is contained in:
@@ -3,6 +3,8 @@ import { throttle } from "lodash";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowRef } from "vue";
|
||||
import type { TrackMetaSchema } from "@/__generated__";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import { FRONTEND_RESOURCES_PATH } from "@/utils";
|
||||
|
||||
const volumeStorage = useLocalStorage<number>("soundtrack.volume", 1);
|
||||
const mutedStorage = useLocalStorage<boolean>("soundtrack.muted", false);
|
||||
@@ -25,8 +27,23 @@ export type PlayerMeta = {
|
||||
duration?: number;
|
||||
coverUrl?: string;
|
||||
folderCoverUrl?: string;
|
||||
gameArtworkUrl?: string;
|
||||
};
|
||||
|
||||
export function resolveSoundtrackGameArtwork(
|
||||
rom: DetailedRom,
|
||||
): string | undefined {
|
||||
const logoPath = rom.ss_metadata?.logo_path;
|
||||
if (logoPath) return `${FRONTEND_RESOURCES_PATH}/${logoPath}`;
|
||||
|
||||
return (
|
||||
rom.path_cover_large ??
|
||||
rom.path_cover_small ??
|
||||
rom.url_cover ??
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
const useSoundtrackPlayer = defineStore("soundtrackPlayer", () => {
|
||||
const track = ref<PlayerTrack | null>(null);
|
||||
const meta = ref<PlayerMeta>({});
|
||||
|
||||
@@ -30,6 +30,7 @@ import type { DetailedRom } from "@/stores/roms";
|
||||
import useSoundtrackPlayer, {
|
||||
type PlayerMeta,
|
||||
type PlayerTrack,
|
||||
resolveSoundtrackGameArtwork,
|
||||
} from "@/stores/soundtrackPlayer";
|
||||
import { FRONTEND_RESOURCES_PATH, formatBytes } from "@/utils";
|
||||
import { useSnackbar } from "@/v2/composables/useSnackbar";
|
||||
@@ -105,6 +106,10 @@ const folderCoverUrl = computed(() => {
|
||||
return cover ? fileUrl(cover.id, cover.file_name) : null;
|
||||
});
|
||||
|
||||
const gameArtworkUrl = computed(() =>
|
||||
resolveSoundtrackGameArtwork(props.rom),
|
||||
);
|
||||
|
||||
// ---------- Metadata fetch ----------
|
||||
const tracksMeta = ref<Map<number, TrackMetaSchema>>(new Map());
|
||||
const isLoadingMeta = ref(false);
|
||||
@@ -127,6 +132,7 @@ function toPlayerMeta(m: TrackMetaSchema | undefined): PlayerMeta {
|
||||
duration: m?.duration_seconds ?? undefined,
|
||||
coverUrl: coverUrlForMeta(m) ?? undefined,
|
||||
folderCoverUrl: folderCoverUrl.value ?? undefined,
|
||||
gameArtworkUrl: gameArtworkUrl.value,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -207,6 +213,7 @@ const activeArtUrl = computed(
|
||||
() =>
|
||||
coverUrlForMeta(activeMeta.value) ??
|
||||
folderCoverUrl.value ??
|
||||
gameArtworkUrl.value ??
|
||||
"/assets/default/album_cover.jpg",
|
||||
);
|
||||
|
||||
@@ -355,16 +362,16 @@ function seekValueText(v: number): string {
|
||||
<div class="r-v2-stp">
|
||||
<!-- Now playing / placeholder header -->
|
||||
<header class="r-v2-stp__now">
|
||||
<div
|
||||
class="r-v2-stp__cover"
|
||||
:class="{ 'r-v2-stp__cover--spinning': activeTrack && isPlaying }"
|
||||
>
|
||||
<img
|
||||
<div class="r-v2-stp__cover">
|
||||
<div
|
||||
v-if="activeArtUrl"
|
||||
:src="activeArtUrl"
|
||||
class="r-v2-stp__cover-img"
|
||||
alt=""
|
||||
/>
|
||||
class="r-v2-stp__cover-rotor"
|
||||
:class="{
|
||||
'r-v2-stp__cover-rotor--spinning': activeTrack && isPlaying,
|
||||
}"
|
||||
>
|
||||
<img :src="activeArtUrl" class="r-v2-stp__cover-img" alt="" />
|
||||
</div>
|
||||
<RIcon v-else icon="mdi-music-note" size="48" />
|
||||
<div
|
||||
v-if="activeTrack && isBuffering"
|
||||
@@ -629,15 +636,24 @@ function seekValueText(v: number): string {
|
||||
0 0 0 4px color-mix(in srgb, black 20%, transparent);
|
||||
}
|
||||
|
||||
.r-v2-stp__cover-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
.r-v2-stp__cover-rotor {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
transform-origin: 50% 50%;
|
||||
transform-box: border-box;
|
||||
animation: r-v2-stp-spin 12s linear infinite;
|
||||
animation-play-state: paused;
|
||||
}
|
||||
|
||||
.r-v2-stp__cover--spinning .r-v2-stp__cover-img {
|
||||
.r-v2-stp__cover-img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
object-position: center;
|
||||
}
|
||||
|
||||
.r-v2-stp__cover-rotor--spinning {
|
||||
animation-play-state: running;
|
||||
}
|
||||
|
||||
@@ -673,7 +689,7 @@ function seekValueText(v: number): string {
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-v2-stp__cover-img {
|
||||
.r-v2-stp__cover-rotor {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ const coverUrl = computed(
|
||||
() =>
|
||||
meta.value.coverUrl ??
|
||||
meta.value.folderCoverUrl ??
|
||||
meta.value.gameArtworkUrl ??
|
||||
"/assets/default/album_cover.jpg",
|
||||
);
|
||||
|
||||
@@ -196,12 +197,13 @@ function openRom() {
|
||||
>
|
||||
<!-- Top row: cover + meta + close/open-rom -->
|
||||
<div class="r-v2-mp__top">
|
||||
<div
|
||||
class="r-v2-mp__disc"
|
||||
:class="{ 'r-v2-mp__disc--spinning': isPlaying }"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<img :src="coverUrl" class="r-v2-mp__disc-img" alt="" />
|
||||
<div class="r-v2-mp__disc" aria-hidden="true">
|
||||
<div
|
||||
class="r-v2-mp__disc-rotor"
|
||||
:class="{ 'r-v2-mp__disc-rotor--spinning': isPlaying }"
|
||||
>
|
||||
<img :src="coverUrl" class="r-v2-mp__disc-img" alt="" />
|
||||
</div>
|
||||
<div v-if="isBuffering" class="r-v2-mp__disc-buffering">
|
||||
<RSpinner :size="20" :width="2" color="white" />
|
||||
</div>
|
||||
@@ -347,16 +349,25 @@ html[data-bp~="sm-and-down"] .r-v2-mp {
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, black 50%, transparent);
|
||||
}
|
||||
.r-v2-mp__disc-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
.r-v2-mp__disc-rotor {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
transform-origin: 50% 50%;
|
||||
transform-box: border-box;
|
||||
animation: r-v2-mp-spin 12s linear infinite;
|
||||
animation-play-state: paused;
|
||||
}
|
||||
.r-v2-mp__disc--spinning .r-v2-mp__disc-img {
|
||||
.r-v2-mp__disc-rotor--spinning {
|
||||
animation-play-state: running;
|
||||
}
|
||||
|
||||
.r-v2-mp__disc-img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
object-position: center;
|
||||
}
|
||||
/* Static vinyl-record spindle — gives the rotation a fixed visual
|
||||
reference so the spin reads as motion rather than a flat circle. */
|
||||
.r-v2-mp__disc::after {
|
||||
@@ -390,7 +401,7 @@ html[data-bp~="sm-and-down"] .r-v2-mp {
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-v2-mp__disc-img {
|
||||
.r-v2-mp__disc-rotor {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user