Skip to content

Commit

Permalink
Fix player bug (#912)
Browse files Browse the repository at this point in the history
* fix player cannot play at the first time

* fix sentence seek
  • Loading branch information
an-lee authored Jul 30, 2024
1 parent 9757161 commit 115afeb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
13 changes: 4 additions & 9 deletions enjoy/src/renderer/components/medias/media-player-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export const MediaPlayerControls = () => {
setTranscriptionDraft,
} = useContext(MediaPlayerProviderContext);
const { EnjoyApp } = useContext(AppSettingsProviderContext);
const { currentHotkeys } = useContext(
HotKeysSettingsProviderContext
);
const { currentHotkeys } = useContext(HotKeysSettingsProviderContext);
const [playMode, setPlayMode] = useState<"loop" | "single" | "all">("single");
const [playbackRate, setPlaybackRate] = useState<number>(1);
const [grouping, setGrouping] = useState(false);
Expand Down Expand Up @@ -332,9 +330,8 @@ export const MediaPlayerControls = () => {
setCurrentSegmentIndex(0);
return;
}
wavesurfer.seekTo(
Math.ceil((segment.startTime / wavesurfer.getDuration()) * 1e8) / 1e8
);
wavesurfer.setScrollTime(segment.startTime);
wavesurfer.setTime(parseFloat(segment.startTime.toFixed(6)));
}, [decoded, transcription?.id, wavesurfer]);

useEffect(() => {
Expand Down Expand Up @@ -372,9 +369,7 @@ export const MediaPlayerControls = () => {

if (currentTime < activeRegion.start || currentTime > activeRegion.end) {
wavesurfer.setScrollTime(activeRegion.start);
wavesurfer.seekTo(
Math.ceil((activeRegion.start / wavesurfer.getDuration()) * 1e8) / 1e8
);
wavesurfer.setTime(parseFloat(activeRegion.start.toFixed(6)));
}
}, [wavesurfer, decoded, playMode, activeRegion, currentTime]);

Expand Down
5 changes: 1 addition & 4 deletions enjoy/src/renderer/components/medias/media-transcription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ export const MediaTranscription = (props: { display?: boolean }) => {
currentSegmentIndex === index ? "bg-yellow-400/25" : ""
}`}
onClick={() => {
const duration = wavesurfer.getDuration();
wavesurfer.seekTo(
Math.floor((sentence.startTime / duration) * 1e8) / 1e8
);
wavesurfer.setTime(parseFloat(sentence.startTime.toFixed(6)));
wavesurfer.setScrollTime(sentence.startTime);
setCurrentSegmentIndex(index);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const RecordingPlayer = (props: {
if (!wavesurfer) return;
if (!seek?.seekTo) return;

wavesurfer.seekTo(seek.seekTo / wavesurfer.getDuration());
wavesurfer.setTime(parseFloat(seek.seekTo.toFixed(6)));
}, [seek, wavesurfer]);

useEffect(() => {
Expand Down

0 comments on commit 115afeb

Please sign in to comment.