Fix whisper should abort when cancel (#692)

* add whisper abort

* abort whisper when exit meida page

* add abort controller for youtubedr
This commit is contained in:
an-lee
2024-06-20 14:23:11 +08:00
committed by GitHub
parent 814be8369d
commit c50e5abf7b
6 changed files with 66 additions and 17 deletions

View File

@@ -178,6 +178,7 @@ export const MediaPlayerProvider = ({
generateTranscription,
transcribing,
transcribingProgress,
abortGenerateTranscription,
} = useTranscriptions(media);
const {
@@ -559,6 +560,18 @@ export const MediaPlayerProvider = ({
};
}, [media?.src, ref, mediaProvider, layout?.playerHeight]);
/* cache last segment index */
useEffect(() => {
if (!media) return;
if (!currentSegmentIndex) return;
setCachedSegmentIndex(currentSegmentIndex);
}, [currentSegmentIndex]);
/*
* Update layout when window is resized
* Abort transcription when component is unmounted
*/
useEffect(() => {
calculateHeight();
@@ -572,17 +585,10 @@ export const MediaPlayerProvider = ({
return () => {
EnjoyApp.window.removeListeners();
abortGenerateTranscription();
};
}, []);
/* cache last segment index */
useEffect(() => {
if (!media) return;
if (!currentSegmentIndex) return;
setCachedSegmentIndex(currentSegmentIndex);
}, [currentSegmentIndex]);
return (
<>
<MediaPlayerProviderContext.Provider