mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-06 19:48:19 +08:00
Ship lighter isolated runtimes, richer Books and Mastery flows, Reading/session polish, and explicit model API capabilities. Release notes: assets/releases/ver1-6-4.md
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
export interface PlayerController {
|
|
currentTime(): number;
|
|
duration(): number;
|
|
seek(seconds: number): void;
|
|
play(): void;
|
|
pause(): void;
|
|
destroy(): void;
|
|
}
|
|
|
|
export interface YouTubePlayerLike {
|
|
getCurrentTime(): number;
|
|
getDuration(): number;
|
|
seekTo(seconds: number, allowSeekAhead: boolean): void;
|
|
playVideo(): void;
|
|
pauseVideo(): void;
|
|
destroy(): void;
|
|
}
|
|
|
|
export function youtubePlayerController(
|
|
player: YouTubePlayerLike,
|
|
): PlayerController {
|
|
return {
|
|
currentTime: () => Number(player.getCurrentTime()) || 0,
|
|
duration: () => Number(player.getDuration()) || 0,
|
|
seek: (seconds) => player.seekTo(Math.max(0, seconds), true),
|
|
play: () => player.playVideo(),
|
|
pause: () => player.pauseVideo(),
|
|
destroy: () => player.destroy(),
|
|
};
|
|
}
|
|
|
|
export function html5PlayerController(
|
|
video: HTMLMediaElement,
|
|
): PlayerController {
|
|
return {
|
|
currentTime: () => Number(video.currentTime) || 0,
|
|
duration: () => Number(video.duration) || 0,
|
|
seek: (seconds) => {
|
|
video.currentTime = Math.max(0, seconds);
|
|
},
|
|
play: () => void video.play(),
|
|
pause: () => video.pause(),
|
|
destroy: () => video.pause(),
|
|
};
|
|
}
|