diff --git a/tauri-app/src/pages/ContentManagement/VoiceMaterialLibrary.tsx b/tauri-app/src/pages/ContentManagement/VoiceMaterialLibrary.tsx index 8ee0c13..a6f3387 100644 --- a/tauri-app/src/pages/ContentManagement/VoiceMaterialLibrary.tsx +++ b/tauri-app/src/pages/ContentManagement/VoiceMaterialLibrary.tsx @@ -38,6 +38,10 @@ export default function VoiceMaterialLibrary() { const fileInputRef = useRef(null); const pollingIds = useRef>(new Set()); + // 音频播放状态 + const [playingId, setPlayingId] = useState(null); + const audioRef = useRef(null); + const { voiceMaterials, avatarMaterials, @@ -504,20 +508,38 @@ export default function VoiceMaterialLibrary() { width: 36, height: 36, borderRadius: '50%', - background: 'var(--bg-secondary)', + background: playingId === m.id ? 'var(--primary-color)' : 'var(--bg-secondary)', + color: playingId === m.id ? '#fff' : 'inherit', display: 'flex', alignItems: 'center', justifyContent: 'center', }} onClick={() => { - const audio = new Audio(m.sourceUrl); - audio.play(); + if (playingId === m.id) { + audioRef.current?.pause(); + setPlayingId(null); + } else { + audioRef.current?.pause(); + const audio = new Audio(m.sourceUrl); + audio.onended = () => setPlayingId(null); + audio.onpause = () => setPlayingId(null); + audio.play(); + audioRef.current = audio; + setPlayingId(m.id); + } }} - title="播放" + title={playingId === m.id ? '暂停' : '播放'} > - - - + {playingId === m.id ? ( + + + + + ) : ( + + + + )} )}