Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/player/src/components/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ export const VideoPlayer = forwardRef<MediaPlayerInstance, MediaPlayerProps>(
if (!videoRef.current) return;

const video = videoRef.current;
const player = new shaka.Player(video);
const player = new shaka.Player();
player.attach(video);
playerRef.current = player;

// Set up error handling
Expand Down Expand Up @@ -364,15 +365,19 @@ export const VideoPlayer = forwardRef<MediaPlayerInstance, MediaPlayerProps>(
},
});
}
await playerRef.current.load(source.src);
await playerRef.current.load(source.src, source.startTime, source.type);
}

onLoadedData?.();
mediaContext?.actions.setLoading(false);
mediaContext?.actions.setError(null);
} catch (error) {
const err =
error instanceof Error ? error : new Error("Failed to load source");
let err;
if (error instanceof Error)
err = error;
else if (error && typeof error === 'object' && 'message' in error && typeof error.message === 'string')
err = new Error(error.message);
else err = new Error("Failed to load source");
onError?.(err);
mediaContext?.actions.setError(err);
mediaContext?.actions.setLoading(false);
Expand Down
1 change: 1 addition & 0 deletions packages/player/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface TextTrack {
// Player source types
export interface PlayerSource {
src: string;
startTime?: number;
type?: string;
drm?: DrmConfig;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/player/src/types/shaka.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ declare module "shaka-player" {
namespace shaka {
export class Player {
constructor(video: HTMLVideoElement);
load(uri: string): Promise<void>;
constructor();
attach(video: HTMLVideoElement);
load(uri: string, startTime ? : number | null , mimeType ? : string | null): Promise<void>;
destroy(): Promise<void>;
configure(config: any): void;
getConfiguration(): any;
Expand Down
Loading