mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-21 07:32:02 +00:00
include PIP api state, only show if PIP enabled
This commit is contained in:
parent
69fea4daac
commit
5bc7040ef6
2 changed files with 36 additions and 10 deletions
|
|
@ -168,9 +168,14 @@ const ControlBar = ({
|
||||||
<Icon className={styles['icon']} name={'more-vertical'} />
|
<Icon className={styles['icon']} name={'more-vertical'} />
|
||||||
</Button>
|
</Button>
|
||||||
<div className={classnames(styles['control-bar-buttons-menu-container'], { 'open': buttonsMenuOpen })}>
|
<div className={classnames(styles['control-bar-buttons-menu-container'], { 'open': buttonsMenuOpen })}>
|
||||||
<Button className={classnames(styles['control-bar-button'], { 'disabled': stream === null })} tabIndex={-1} onClick={onPipButtonClick}>
|
{
|
||||||
<Icon className={styles['icon']} name={'open-in-browser'} />
|
document.pictureInPictureEnabled ?
|
||||||
</Button>
|
<Button className={classnames(styles['control-bar-button'], { 'disabled': stream === null })} tabIndex={-1} onClick={onPipButtonClick}>
|
||||||
|
<Icon className={styles['icon']} name={'open-in-browser'} />
|
||||||
|
</Button>
|
||||||
|
:
|
||||||
|
null
|
||||||
|
}
|
||||||
<Button className={classnames(styles['control-bar-button'], { 'disabled': statistics === null || statistics.type === 'Err' || stream === null || typeof stream.infoHash !== 'string' || typeof stream.fileIdx !== 'number' })} tabIndex={-1} onMouseDown={onStatisticsButtonMouseDown} onClick={onToggleStatisticsMenu}>
|
<Button className={classnames(styles['control-bar-button'], { 'disabled': statistics === null || statistics.type === 'Err' || stream === null || typeof stream.infoHash !== 'string' || typeof stream.fileIdx !== 'number' })} tabIndex={-1} onMouseDown={onStatisticsButtonMouseDown} onClick={onToggleStatisticsMenu}>
|
||||||
<Icon className={styles['icon']} name={'network'} />
|
<Icon className={styles['icon']} name={'network'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -279,18 +279,39 @@ const Player = ({ urlParams, queryParams }) => {
|
||||||
const onPipEnableRequested = React.useCallback(() => {
|
const onPipEnableRequested = React.useCallback(() => {
|
||||||
console.log("Entering picture in picture");
|
console.log("Entering picture in picture");
|
||||||
const videoElement = video.containerRef.current?.querySelector('video');
|
const videoElement = video.containerRef.current?.querySelector('video');
|
||||||
videoElement.requestPictureInPicture().then(() => {
|
if (videoElement && videoElement !== document.pictureInPictureElement) {
|
||||||
video.setPictureInPicture(true);
|
videoElement.requestPictureInPicture();
|
||||||
});
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onPipDisableRequested = React.useCallback(() => {
|
const onPipDisableRequested = React.useCallback(() => {
|
||||||
console.log("Exiting picture in picture");
|
if (document.pictureInPictureElement) {
|
||||||
document.exitPictureInPicture().then(() => {
|
document.exitPictureInPicture();
|
||||||
video.setPictureInPicture(false);
|
}
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Listen to PiP events to sync state
|
||||||
|
React.useEffect(() => {
|
||||||
|
const videoElement = video.containerRef.current?.querySelector('video');
|
||||||
|
if (!videoElement) return;
|
||||||
|
|
||||||
|
const onEnterPip = () => {
|
||||||
|
video.setPictureInPicture(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onLeavePip = () => {
|
||||||
|
video.setPictureInPicture(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
videoElement.addEventListener('enterpictureinpicture', onEnterPip);
|
||||||
|
videoElement.addEventListener('leavepictureinpicture', onLeavePip);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
videoElement.removeEventListener('enterpictureinpicture', onEnterPip);
|
||||||
|
videoElement.removeEventListener('leavepictureinpicture', onLeavePip);
|
||||||
|
};
|
||||||
|
}, [video.state.stream]);
|
||||||
|
|
||||||
const onVideoClick = React.useCallback(() => {
|
const onVideoClick = React.useCallback(() => {
|
||||||
if (video.state.paused !== null) {
|
if (video.state.paused !== null) {
|
||||||
if (video.state.paused) {
|
if (video.state.paused) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue