diff --git a/src/app/music/page.tsx b/src/app/music/page.tsx index 091abbc..dde84d3 100644 --- a/src/app/music/page.tsx +++ b/src/app/music/page.tsx @@ -6,19 +6,12 @@ import EnterQueyueBtn from '@/components/EnterQueyueBtn'; import MusicBanner from '@/components/MusicBanner'; import MusicPanel from '@/components/MusicPanel'; -async function getMusic(songId: string) { - const res = await fetch(`http://api.indie.cn:9012/luoo-music/song/${songId}`); - return res.json(); -} - -export default async function Music({ searchParams: { id } }: any) { - const res = await getMusic(id); - const musicInfo = res?.data; +export default async function Music() { return (
- +
diff --git a/src/components/AudioPlayer/index.tsx b/src/components/AudioPlayer/index.tsx index 016f778..a0960c1 100644 --- a/src/components/AudioPlayer/index.tsx +++ b/src/components/AudioPlayer/index.tsx @@ -106,7 +106,7 @@ export default forwardRef(function AudioPlayer( onTouchEnd={handleSlideEnd} onChange={handleSlideChange} /> -
+
{curTime}
{totalTime}
diff --git a/src/components/MusicPanel/index.tsx b/src/components/MusicPanel/index.tsx index b391be5..d579849 100644 --- a/src/components/MusicPanel/index.tsx +++ b/src/components/MusicPanel/index.tsx @@ -7,8 +7,14 @@ import Image from 'next/image'; import AudioPlayer from '@/components/AudioPlayer'; import type { IAudioPlayerRef } from '@/components/AudioPlayer'; -export default function MusicPanel(props: { musicInfo: ISong }) { - const { musicInfo } = props || {}; +async function getMusic(songId: string) { + const res = await fetch(`http://api.indie.cn:9012/luoo-music/song/${songId}`); + return res.json(); +} + +export default function MusicPanel() { + const [musicInfo, setMusicInfo] = useState(); + const [loading, setLoading] = useState(true); const audioPlayerRef = useRef(null); const [playing, setPlaying] = useState(false); @@ -22,46 +28,70 @@ export default function MusicPanel(props: { musicInfo: ISong }) { }; useEffect(() => { - setPlaying(!!!audioPlayerRef.current?.audio?.paused); + const { searchParams } = new URL(window.location.href); + setLoading(true); + getMusic((searchParams as any)?.get('id')) + .then((res) => { + setMusicInfo(res?.data); + }) + .finally(() => { + setLoading(false); + }); }, []); + useEffect(() => { + if (!loading && musicInfo?.src) { + audioPlayerRef.current?.audio?.play(); + setPlaying(!!!audioPlayerRef.current?.audio?.paused); + } + }, [loading, musicInfo]); + return ( - <> -
- cover - pause - play -
+
+ {loading && ( +
+ 加载中 ... +
+ )} +
+
+ {musicInfo?.pic && ( + cover + )} + pause + play +
-
-
- VOL {musicInfo?.journalNo} +
+
+ VOL {musicInfo?.journalNo} +
-
-
{musicInfo?.title}
-

- {[musicInfo?.artist, musicInfo?.album].filter((str) => !!str).join(' / ')} -

+
{musicInfo?.title}
+

+ {[musicInfo?.artist, musicInfo?.album].filter((str) => !!str).join(' / ')} +

-
- +
+ +
- +
); }