|
|
|
@ -6,59 +6,59 @@ class VideoManagerService { |
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
if (!VideoManagerService.instance) { |
|
|
|
if (!VideoManagerService.instance) { |
|
|
|
VideoManagerService.instance = this |
|
|
|
VideoManagerService.instance = this |
|
|
|
document.addEventListener('leavepictureinpicture', (e) => { |
|
|
|
|
|
|
|
;(e.target as HTMLVideoElement).pause() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return VideoManagerService.instance |
|
|
|
return VideoManagerService.instance |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enterPiP(video: HTMLVideoElement) { |
|
|
|
pause(video: HTMLVideoElement) { |
|
|
|
if (this.currentVideo && this.currentVideo !== video) { |
|
|
|
if (isPipElement(video)) { |
|
|
|
this.exitPiP(this.currentVideo) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.currentVideo === video) { |
|
|
|
if ( |
|
|
|
this.currentVideo = null |
|
|
|
(video as any).webkitSupportsPresentationMode && |
|
|
|
|
|
|
|
typeof (video as any).webkitSetPresentationMode === 'function' |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
;(video as any).webkitSetPresentationMode('picture-in-picture') |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
if ((video as any).webkitPresentationMode !== 'picture-in-picture') { |
|
|
|
|
|
|
|
video.pause() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 10) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
video.requestPictureInPicture().catch(() => { |
|
|
|
|
|
|
|
video.pause() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
video.pause() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private exitPiP(video: HTMLVideoElement) { |
|
|
|
autoPlay(video: HTMLVideoElement) { |
|
|
|
video.pause() |
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
(video as any).webkitSupportsPresentationMode && |
|
|
|
document.pictureInPictureElement && |
|
|
|
typeof (video as any).webkitSetPresentationMode === 'function' |
|
|
|
isVideoPlaying(document.pictureInPictureElement as HTMLVideoElement) |
|
|
|
) { |
|
|
|
) { |
|
|
|
;(video as any).webkitSetPresentationMode('inline') |
|
|
|
return |
|
|
|
} else { |
|
|
|
|
|
|
|
document.exitPictureInPicture() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.currentVideo === video) { |
|
|
|
|
|
|
|
this.currentVideo = null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.play(video) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async playVideo(video: HTMLVideoElement) { |
|
|
|
play(video: HTMLVideoElement) { |
|
|
|
|
|
|
|
if (document.pictureInPictureElement && document.pictureInPictureElement !== video) { |
|
|
|
|
|
|
|
;(document.pictureInPictureElement as HTMLVideoElement).pause() |
|
|
|
|
|
|
|
} |
|
|
|
if (this.currentVideo && this.currentVideo !== video) { |
|
|
|
if (this.currentVideo && this.currentVideo !== video) { |
|
|
|
this.exitPiP(this.currentVideo) |
|
|
|
this.currentVideo.pause() |
|
|
|
} |
|
|
|
} |
|
|
|
this.currentVideo = video |
|
|
|
this.currentVideo = video |
|
|
|
video.play() |
|
|
|
if (isVideoPlaying(video)) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.currentVideo.play().catch((error) => { |
|
|
|
|
|
|
|
console.error('Error playing video:', error) |
|
|
|
|
|
|
|
this.currentVideo = null |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const instance = new VideoManagerService() |
|
|
|
const instance = new VideoManagerService() |
|
|
|
export default instance |
|
|
|
export default instance |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isVideoPlaying(video: HTMLVideoElement) { |
|
|
|
|
|
|
|
return video.currentTime > 0 && !video.paused && !video.ended && video.readyState >= 2 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isPipElement(video: HTMLVideoElement) { |
|
|
|
|
|
|
|
if (document.pictureInPictureElement === video) { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return (video as any).webkitPresentationMode === 'picture-in-picture' |
|
|
|
|
|
|
|
} |
|
|
|
|