feat: add PiP, fullscreen, and playbackRate helpers to playback module
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -96,6 +96,58 @@ export function adjustShuttle(dir: 1 | -1, shuttleRate: number): number {
|
||||
return nextRate;
|
||||
}
|
||||
|
||||
export function togglePiP(): void {
|
||||
if (document.pictureInPictureElement) {
|
||||
document.exitPictureInPicture().catch((e) => {
|
||||
console.error('Exit PiP failed:', e);
|
||||
});
|
||||
} else {
|
||||
const videoEl = getVideo();
|
||||
if (videoEl && document.pictureInPictureEnabled) {
|
||||
videoEl.requestPictureInPicture().catch((e) => {
|
||||
console.error('PiP request failed:', e);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isPiPActive(): boolean {
|
||||
return !!document.pictureInPictureElement;
|
||||
}
|
||||
|
||||
export function toggleFullscreen(): void {
|
||||
if (document.fullscreenElement) {
|
||||
document.exitFullscreen().catch((e) => {
|
||||
console.error('Exit fullscreen failed:', e);
|
||||
});
|
||||
} else {
|
||||
const videoEl = getVideo();
|
||||
if (!videoEl) return;
|
||||
if (videoEl.requestFullscreen) {
|
||||
videoEl.requestFullscreen().catch((e) => {
|
||||
console.error('Fullscreen request failed:', e);
|
||||
});
|
||||
} else if ((videoEl as HTMLVideoElement & { webkitEnterFullscreen?: () => void }).webkitEnterFullscreen) {
|
||||
(videoEl as HTMLVideoElement & { webkitEnterFullscreen: () => void }).webkitEnterFullscreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isFullscreenActive(): boolean {
|
||||
return !!document.fullscreenElement;
|
||||
}
|
||||
|
||||
export function setPlaybackRate(rate: number): void {
|
||||
const videoEl = getVideo();
|
||||
if (videoEl) {
|
||||
videoEl.playbackRate = rate;
|
||||
}
|
||||
}
|
||||
|
||||
export function getPlaybackRate(): number {
|
||||
return getVideo()?.playbackRate ?? 1;
|
||||
}
|
||||
|
||||
export type TransportKeyAction =
|
||||
| 'play-pause'
|
||||
| 'frame-back'
|
||||
|
||||
Reference in New Issue
Block a user