You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
class VideoManager { |
|
private static currentVideo: HTMLVideoElement | null = null |
|
|
|
static async enterPiP(video: HTMLVideoElement) { |
|
if (VideoManager.currentVideo && VideoManager.currentVideo !== video) { |
|
await VideoManager.exitPiP(VideoManager.currentVideo) |
|
} |
|
|
|
if ('requestPictureInPicture' in video) { |
|
await video.requestPictureInPicture() |
|
} else if ('webkitSetPresentationMode' in video) { |
|
;(video as any).webkitSetPresentationMode('picture-in-picture') |
|
} |
|
} |
|
|
|
static async exitPiP(video: HTMLVideoElement) { |
|
video.pause() |
|
if (document.pictureInPictureElement === video) { |
|
await document.exitPictureInPicture() |
|
} else if ('webkitSetPresentationMode' in video) { |
|
;(video as any).webkitSetPresentationMode('inline') |
|
} |
|
|
|
if (VideoManager.currentVideo === video) { |
|
VideoManager.currentVideo = null |
|
} |
|
} |
|
|
|
static async playVideo(video: HTMLVideoElement) { |
|
if (VideoManager.currentVideo && VideoManager.currentVideo !== video) { |
|
await VideoManager.exitPiP(VideoManager.currentVideo) |
|
} |
|
VideoManager.currentVideo = video |
|
video.play() |
|
} |
|
} |
|
|
|
export default VideoManager
|
|
|