fix: 录音中 暂停语音播放

This commit is contained in:
2025-10-17 10:14:56 +08:00
parent 81fd471fd9
commit bfa3d914e8

View File

@@ -17,11 +17,13 @@ function Index(props: DefinedProps) {
const [isPlaying, setIsPlating] = useState(false); const [isPlaying, setIsPlating] = useState(false);
const [currentPlayingId, setCurrentPlayingId] = useState<number>(); const [currentPlayingId, setCurrentPlayingId] = useState<number>();
// useEffect(() => { useEffect(() => {
// if (isRecording) { if (isRecording && currentPlayingId) {
// stopAllAudio(); audioRefs.current[currentPlayingId].pause();
// } audioRefs.current[currentPlayingId].currentTime = 0;
// }, [isRecording]); setCurrentPlayingId(undefined);
}
}, [isRecording, currentPlayingId]);
const playAudio = (id: number, audioUrl: string) => { const playAudio = (id: number, audioUrl: string) => {
if (isRecording) { if (isRecording) {
@@ -45,22 +47,7 @@ function Index(props: DefinedProps) {
setCurrentPlayingId(undefined); setCurrentPlayingId(undefined);
} }
}; };
// const stopAllAudio = () => {
// if (currentPlayingId && audioRefs.current[currentPlayingId]) {
// audioRefs.current[currentPlayingId].pause();
// audioRefs.current[currentPlayingId].currentTime = 0;
// setIsPlating(false);
// setCurrentPlayingId(undefined);
// return;
// }
// Object.values(audioRefs.current).forEach((audio) => {
// if (!audio.paused) {
// audio.pause();
// audio.currentTime = 0;
// }
// });
// };
const renderAvatar = (item: Message) => { const renderAvatar = (item: Message) => {
return <Avatar src={item.petAvatar || ""} style={{ "--border-radius": "32px" }} />; return <Avatar src={item.petAvatar || ""} style={{ "--border-radius": "32px" }} />;
}; };
@@ -132,32 +119,6 @@ function Index(props: DefinedProps) {
<div className="time">{item.contentDuration}''</div> <div className="time">{item.contentDuration}''</div>
</div> </div>
{renderTranslateResult(item)} {renderTranslateResult(item)}
{/* {item.isTranslating ? (
<div className="translate">
<SpinLoading color="default" style={{ "--size": "12px" }} />
<span>翻译中...</span>
</div>
) : item.transStatus === 1 ? (
<div className="translate">
{item.transResult?.length ? (
item.transResult
) : (
<Space justify={"between"}>
<span>未知语句</span>
<Refresh onClick={(e) => refreshMessage(item.id, e)} size="12" fill="#333" />
</Space>
)}
</div>
) : (
<Space justify={"between"} className="translate">
<span>翻译失败,请重试</span>
<Refresh onClick={(e) => refreshMessage(item.id, e)} size="12" fill="#333" />
</Space>
// <div className="translate">
// <span> 翻译失败,请重试</span>
// <Refresh onClick={(e) => refreshMessage(item.id, e)} size="12" fill="#333" />
// </div>
)} */}
</div> </div>
</div> </div>
))} ))}