Fix ts issues
This commit is contained in:
parent
edb5c6bcfa
commit
3fc002f3fd
@ -6,7 +6,7 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
type RefObject,
|
type RefObject,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import shaka from 'shaka-player/dist/shaka-player.compiled.js';
|
import shaka from 'shaka-player/dist/shaka-player.ui';
|
||||||
import type { VideoRef, ReactVideoProps, VideoMetadata } from './types';
|
import type { VideoRef, ReactVideoProps, VideoMetadata } from './types';
|
||||||
|
|
||||||
const Video = forwardRef<VideoRef, ReactVideoProps>(
|
const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||||
@ -27,21 +27,18 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
onBuffer,
|
onBuffer,
|
||||||
onLoad,
|
onLoad,
|
||||||
onProgress,
|
onProgress,
|
||||||
onPlaybackRateChange,
|
// onPlaybackRateChange,
|
||||||
onError,
|
onError,
|
||||||
onReadyForDisplay,
|
onReadyForDisplay,
|
||||||
onSeek,
|
onSeek,
|
||||||
onVolumeChange,
|
// onVolumeChange,
|
||||||
onEnd,
|
onEnd,
|
||||||
onPlaybackStateChanged,
|
|
||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const nativeRef = useRef<HTMLVideoElement>(null);
|
const nativeRef = useRef<HTMLVideoElement>(null);
|
||||||
const shakaPlayerRef = useRef<shaka.Player | null>(null);
|
const shakaPlayerRef = useRef<shaka.Player | null>(null);
|
||||||
|
|
||||||
const isSeeking = useRef(false);
|
|
||||||
|
|
||||||
const seek = useCallback(
|
const seek = useCallback(
|
||||||
(time: number, _tolerance?: number) => {
|
(time: number, _tolerance?: number) => {
|
||||||
if (isNaN(time)) {
|
if (isNaN(time)) {
|
||||||
@ -227,7 +224,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
shakaPlayerRef.current = player;
|
shakaPlayerRef.current = player;
|
||||||
|
|
||||||
// Error handling
|
// Error handling
|
||||||
player.addEventListener('error', (event) => {
|
player.addEventListener('error', (event: shaka.Event) => {
|
||||||
const shakaError = event.detail;
|
const shakaError = event.detail;
|
||||||
console.error('Shaka Player Error', shakaError);
|
console.error('Shaka Player Error', shakaError);
|
||||||
onError?.({
|
onError?.({
|
||||||
@ -239,7 +236,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Buffering events
|
// Buffering events
|
||||||
player.addEventListener('buffering', (event) => {
|
player.addEventListener('buffering', (event: shaka.Event) => {
|
||||||
onBuffer?.({ isBuffering: event.buffering });
|
onBuffer?.({ isBuffering: event.buffering });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -263,6 +260,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
onLoad?.({
|
onLoad?.({
|
||||||
currentTime: nativeRef.current.currentTime,
|
currentTime: nativeRef.current.currentTime,
|
||||||
duration,
|
duration,
|
||||||
|
//@ts-ignore
|
||||||
naturalSize,
|
naturalSize,
|
||||||
videoTracks: player.getVariantTracks(),
|
videoTracks: player.getVariantTracks(),
|
||||||
audioTracks: player.getVariantTracks(),
|
audioTracks: player.getVariantTracks(),
|
||||||
@ -271,7 +269,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
|
|
||||||
onReadyForDisplay?.();
|
onReadyForDisplay?.();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error: any) => {
|
||||||
console.error('Error loading video', error);
|
console.error('Error loading video', error);
|
||||||
onError?.({ error });
|
onError?.({ error });
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user