This commit is contained in:
an-lee
2024-07-17 09:54:24 +08:00
parent 9bb7133fb7
commit 10971b108f

View File

@@ -251,6 +251,11 @@ export const MediaPlayerControls = () => {
.getRegions()
.find((r) => r.id === `segment-region-${currentSegmentIndex}`);
const activeRegionDebouncePlay = debounce(() => {
console.log("play loop");
activeRegion?.play();
}, 100);
const subscriptions = [
wavesurfer.on("finish", () => {
if (playMode !== "loop") return;
@@ -301,7 +306,7 @@ export const MediaPlayerControls = () => {
if (playMode === "loop") {
wavesurfer.pause();
setTimeout(() => {
activeRegion.play();
activeRegionDebouncePlay();
}, 500);
} else if (playMode === "single") {
wavesurfer.pause();
@@ -329,7 +334,7 @@ export const MediaPlayerControls = () => {
return;
}
wavesurfer.seekTo(
Math.floor((segment.startTime / wavesurfer.getDuration()) * 1e8) / 1e8
Math.ceil((segment.startTime / wavesurfer.getDuration()) * 1e8) / 1e8
);
}, [decoded, transcription?.id, wavesurfer]);
@@ -369,7 +374,7 @@ export const MediaPlayerControls = () => {
if (currentTime < activeRegion.start || currentTime > activeRegion.end) {
wavesurfer.setScrollTime(activeRegion.start);
wavesurfer.seekTo(
Math.floor((activeRegion.start / wavesurfer.getDuration()) * 1e8) / 1e8
Math.ceil((activeRegion.start / wavesurfer.getDuration()) * 1e8) / 1e8
);
}
}, [wavesurfer, decoded, playMode, activeRegion, currentTime]);