From 8542c8f7d1c42fc6dca0e88c264004dc57bc086a Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 16 Jul 2024 11:44:05 +0700 Subject: [PATCH] Add isSeeking on web --- src/Video.web.tsx | 22 +++++++++++++++++++--- src/VideoDecoderProperties.web.ts | 4 ++-- src/specs/NativeVideoDecoderInfoModule.ts | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Video.web.tsx b/src/Video.web.tsx index 61631252..85f71a92 100644 --- a/src/Video.web.tsx +++ b/src/Video.web.tsx @@ -38,6 +38,7 @@ const Video = forwardRef( ) => { const nativeRef = useRef(null); + const isSeeking = useRef(false); const seek = useCallback( async (time: number, _tolerance?: number) => { if (isNaN(time)) { @@ -210,7 +211,10 @@ const Video = forwardRef( // Set play state to the player's value (if autoplay is denied) // This is useful if our UI is in a play state but autoplay got denied so // the video is actaully in a paused state. - playbackStateRef.current?.({isPlaying: !nativeRef.current.paused}); + playbackStateRef.current?.({ + isPlaying: !nativeRef.current.paused, + isSeeking: isSeeking.current, + }); }, 500); }, []); @@ -291,8 +295,20 @@ const Video = forwardRef( seek(source.startPosition / 1000); } }} - onPlay={() => onPlaybackStateChanged?.({isPlaying: true})} - onPause={() => onPlaybackStateChanged?.({isPlaying: false})} + onPlay={() => + onPlaybackStateChanged?.({ + isPlaying: true, + isSeeking: isSeeking.current, + }) + } + onPause={() => + onPlaybackStateChanged?.({ + isPlaying: false, + isSeeking: isSeeking.current, + }) + } + onSeeking={() => (isSeeking.current = true)} + onSeeked={() => (isSeeking.current = false)} onVolumeChange={() => { if (!nativeRef.current) { return; diff --git a/src/VideoDecoderProperties.web.ts b/src/VideoDecoderProperties.web.ts index 3f986694..ce49b498 100644 --- a/src/VideoDecoderProperties.web.ts +++ b/src/VideoDecoderProperties.web.ts @@ -1,5 +1,5 @@ /// -import type {VideoDecoderPropertiesType} from './specs/VideoNativeComponent'; +import type {VideoDecoderInfoModuleType} from './specs/NativeVideoDecoderInfoModule'; const canPlay = (codec: string): boolean => { // most chrome based browser (and safari I think) supports matroska but reports they do not. @@ -31,4 +31,4 @@ export const VideoDecoderProperties = { ? 'software' : 'unsupported'; }, -} satisfies VideoDecoderPropertiesType; +} satisfies VideoDecoderInfoModuleType; diff --git a/src/specs/NativeVideoDecoderInfoModule.ts b/src/specs/NativeVideoDecoderInfoModule.ts index 25cf9cc2..060fb0fd 100644 --- a/src/specs/NativeVideoDecoderInfoModule.ts +++ b/src/specs/NativeVideoDecoderInfoModule.ts @@ -2,7 +2,7 @@ import {NativeModules} from 'react-native'; import type {Int32} from 'react-native/Libraries/Types/CodegenTypes'; // @TODO rename to "Spec" when applying new arch -interface VideoDecoderInfoModuleType { +export interface VideoDecoderInfoModuleType { getWidevineLevel: () => Promise; isCodecSupported: ( mimeType: string,