diff --git a/index.html b/index.html
index 6478b7d..049df05 100644
--- a/index.html
+++ b/index.html
@@ -319,7 +319,7 @@
);
- const SideDrawer = ({ isOpen, onClose, view, setView, quality, setQuality }) => {
+ const SideDrawer = ({ isOpen, onClose, view, setView, quality, setQuality, onClearCache }) => {
if (!isOpen) return null;
return (
@@ -355,8 +355,8 @@
设置
-
+
+
+
+
@@ -719,17 +734,6 @@
audio.volume = volume;
const updateTime = () => {
setCurrentTime(audio.currentTime);
- if ('mediaSession' in navigator && !isNaN(audio.duration)) {
- try {
- navigator.mediaSession.setPositionState({
- duration: audio.duration,
- playbackRate: audio.playbackRate,
- position: audio.currentTime
- });
- } catch (e) {
- // Ignore errors
- }
- }
};
const updateDuration = () => setDuration(audio.duration);
const onEnded = () => playNext(true);
@@ -878,8 +882,11 @@
};
const handleSeek = (time) => {
- audioRef.current.currentTime = time;
- setCurrentTime(time);
+ if (Number.isFinite(time)) {
+ audioRef.current.currentTime = time;
+ setCurrentTime(time);
+ updateMediaSessionPosition();
+ }
};
const deleteFromPlaylist = (index) => {
@@ -915,6 +922,18 @@
// --- Media Session Integration ---
+ const updateMediaSessionPosition = () => {
+ if ('mediaSession' in navigator && audioRef.current && !isNaN(audioRef.current.duration)) {
+ try {
+ navigator.mediaSession.setPositionState({
+ duration: audioRef.current.duration,
+ playbackRate: audioRef.current.playbackRate,
+ position: audioRef.current.currentTime
+ });
+ } catch (e) { console.error("MediaSession Position Error:", e); }
+ }
+ };
+
// Update refs for Media Session actions
useEffect(() => {
playNextRef.current = playNext;
@@ -958,24 +977,34 @@
}
}, [currentSong]);
- // Media Session Playback State
+ // Media Session Playback State & Position
useEffect(() => {
if ('mediaSession' in navigator) {
navigator.mediaSession.playbackState = isPlaying ? 'playing' : 'paused';
+ updateMediaSessionPosition();
}
}, [isPlaying]);
+ // Update position when song loads
+ useEffect(() => {
+ const audio = audioRef.current;
+ const onLoadedMetadata = () => updateMediaSessionPosition();
+ audio.addEventListener('loadedmetadata', onLoadedMetadata);
+ return () => audio.removeEventListener('loadedmetadata', onLoadedMetadata);
+ }, []);
+
// --- Render ---
return (
- setShowSideDrawer(false)}
view={view}
setView={setView}
quality={quality}
setQuality={setQuality}
+ onClearCache={handleClearCache}
/>
{/* Top Navigation / Search Bar */}