Merge pull request #1756 from OdyseeTeam/dont-dispose-when-switching
Don't dispose switching between video/livestream, chapter button fix, current time not updating quickly fix
This commit is contained in:
commit
3f44b80603
3 changed files with 38 additions and 22 deletions
|
@ -184,6 +184,8 @@ export function parseAndLoad(player: any, claim: StreamClaim) {
|
||||||
overrideHoverTooltip(player, tsData, duration);
|
overrideHoverTooltip(player, tsData, duration);
|
||||||
} else {
|
} else {
|
||||||
deleteHoverInformation(player);
|
deleteHoverInformation(player);
|
||||||
|
// $FlowIssue
|
||||||
|
player?.controlBar?.getChild('ChaptersButton')?.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ type Props = {
|
||||||
activeLivestreamForChannel: any,
|
activeLivestreamForChannel: any,
|
||||||
doToast: ({ message: string, linkText: string, linkTarget: string }) => void,
|
doToast: ({ message: string, linkText: string, linkTarget: string }) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
const VIDEOJS_VOLUME_PANEL_CLASS = 'VolumePanel';
|
const VIDEOJS_VOLUME_PANEL_CLASS = 'VolumePanel';
|
||||||
|
|
||||||
const IS_IOS = platform.isIOS();
|
const IS_IOS = platform.isIOS();
|
||||||
|
@ -250,17 +251,17 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
muted: startMuted,
|
muted: startMuted,
|
||||||
plugins: { eventTracking: true, overlay: OVERLAY.OVERLAY_DATA },
|
plugins: { eventTracking: true, overlay: OVERLAY.OVERLAY_DATA },
|
||||||
controlBar: {
|
controlBar: {
|
||||||
currentTimeDisplay: !isLivestreamClaim,
|
currentTimeDisplay: true,
|
||||||
timeDivider: !isLivestreamClaim,
|
timeDivider: true,
|
||||||
durationDisplay: !isLivestreamClaim,
|
durationDisplay: true,
|
||||||
remainingTimeDisplay: !isLivestreamClaim,
|
remainingTimeDisplay: true,
|
||||||
subsCapsButton: !IS_IOS,
|
subsCapsButton: !IS_IOS,
|
||||||
},
|
},
|
||||||
techOrder: ['chromecast', 'html5'],
|
techOrder: ['chromecast', 'html5'],
|
||||||
...Chromecast.getOptions(),
|
...Chromecast.getOptions(),
|
||||||
bigPlayButton: embedded, // only show big play button if embedded
|
bigPlayButton: embedded, // only show big play button if embedded
|
||||||
liveui: isLivestreamClaim,
|
|
||||||
suppressNotSupportedError: true,
|
suppressNotSupportedError: true,
|
||||||
|
liveui: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: would be nice to pull this out into functions file
|
// TODO: would be nice to pull this out into functions file
|
||||||
|
@ -352,17 +353,6 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
|
|
||||||
let canUseOldPlayer = window.oldSavedDiv && vjsParent;
|
let canUseOldPlayer = window.oldSavedDiv && vjsParent;
|
||||||
const isLivestream = isLivestreamClaim && userClaimId;
|
const isLivestream = isLivestreamClaim && userClaimId;
|
||||||
// make an additional check and reinstantiate if switching between player types
|
|
||||||
// switching between types on iOS causes issues and this is a faster solution
|
|
||||||
if (vjsParent && window.player) {
|
|
||||||
const oldVideoType = window.player.isLivestream ? 'livestream' : 'video';
|
|
||||||
const switchFromLivestreamToVideo = oldVideoType === 'livestream' && !isLivestream;
|
|
||||||
const switchFromVideoToLivestream = oldVideoType === 'video' && isLivestream;
|
|
||||||
if (switchFromLivestreamToVideo || switchFromVideoToLivestream) {
|
|
||||||
canUseOldPlayer = false;
|
|
||||||
window.player.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize videojs if it hasn't been done yet
|
// initialize videojs if it hasn't been done yet
|
||||||
if (!canUseOldPlayer) {
|
if (!canUseOldPlayer) {
|
||||||
|
@ -378,6 +368,27 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
vjsPlayer = window.player;
|
vjsPlayer = window.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hide unused elements on livestream
|
||||||
|
if (isLivestream) {
|
||||||
|
vjsPlayer.addClass('vjs-live');
|
||||||
|
vjsPlayer.addClass('vjs-liveui');
|
||||||
|
// $FlowIssue
|
||||||
|
vjsPlayer.controlBar.currentTimeDisplay?.el().style.setProperty('display', 'none', 'important');
|
||||||
|
// $FlowIssue
|
||||||
|
vjsPlayer.controlBar.timeDivider?.el().style.setProperty('display', 'none', 'important');
|
||||||
|
// $FlowIssue
|
||||||
|
vjsPlayer.controlBar.durationDisplay?.el().style.setProperty('display', 'none', 'important');
|
||||||
|
} else {
|
||||||
|
vjsPlayer.removeClass('vjs-live');
|
||||||
|
vjsPlayer.removeClass('vjs-liveui');
|
||||||
|
// $FlowIssue
|
||||||
|
vjsPlayer.controlBar.currentTimeDisplay?.el().style.setProperty('display', 'block', 'important');
|
||||||
|
// $FlowIssue
|
||||||
|
vjsPlayer.controlBar.timeDivider?.el().style.setProperty('display', 'block', 'important');
|
||||||
|
// $FlowIssue
|
||||||
|
vjsPlayer.controlBar.durationDisplay?.el().style.setProperty('display', 'block', 'important');
|
||||||
|
}
|
||||||
|
|
||||||
// Add recsys plugin
|
// Add recsys plugin
|
||||||
if (shareTelemetry) {
|
if (shareTelemetry) {
|
||||||
vjsPlayer.recsys.options_ = {
|
vjsPlayer.recsys.options_ = {
|
||||||
|
@ -548,6 +559,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('keydown', keyDownHandlerRef.current);
|
window.removeEventListener('keydown', keyDownHandlerRef.current);
|
||||||
|
|
||||||
const containerDiv = containerRef.current;
|
const containerDiv = containerRef.current;
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
containerDiv && containerDiv.removeEventListener('wheel', videoScrollHandlerRef.current);
|
containerDiv && containerDiv.removeEventListener('wheel', videoScrollHandlerRef.current);
|
||||||
|
@ -563,6 +575,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const player = playerRef.current;
|
const player = playerRef.current;
|
||||||
|
|
||||||
if (player) {
|
if (player) {
|
||||||
try {
|
try {
|
||||||
window.cast.framework.CastContext.getInstance().getCurrentSession().endSession(false);
|
window.cast.framework.CastContext.getInstance().getCurrentSession().endSession(false);
|
||||||
|
@ -578,9 +591,6 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
window.player.controlBar?.playToggle?.hide();
|
window.player.controlBar?.playToggle?.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// $FlowIssue
|
|
||||||
window.player?.controlBar?.getChild('ChaptersButton')?.hide();
|
|
||||||
|
|
||||||
// this solves an issue with portrait videos
|
// this solves an issue with portrait videos
|
||||||
// $FlowIssue
|
// $FlowIssue
|
||||||
const videoDiv = window.player?.tech_?.el(); // video element
|
const videoDiv = window.player?.tech_?.el(); // video element
|
||||||
|
@ -592,11 +602,14 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
|
|
||||||
window.player.trigger('playerClosed');
|
window.player.trigger('playerClosed');
|
||||||
|
|
||||||
window.player.currentTime(0);
|
|
||||||
|
|
||||||
// stop streams running in background
|
// stop streams running in background
|
||||||
window.player.loadTech_('html5', null);
|
window.player.loadTech_('html5', null);
|
||||||
|
|
||||||
|
window.player.currentTime(0);
|
||||||
|
|
||||||
|
// makes the current time update immediately
|
||||||
|
window.player.trigger('timeupdate');
|
||||||
|
|
||||||
window.player.claimSrcVhs = null;
|
window.player.claimSrcVhs = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -451,7 +451,8 @@ function VideoViewer(props: Props) {
|
||||||
// turn off old events to prevent duplicate runs
|
// turn off old events to prevent duplicate runs
|
||||||
player.on('playerClosed', cancelOldEvents);
|
player.on('playerClosed', cancelOldEvents);
|
||||||
|
|
||||||
Chapters.parseAndLoad(player, claim);
|
// add (or remove) chapters button and time tooltips when video is ready
|
||||||
|
player.one('loadstart', () => Chapters.parseAndLoad(player, claim));
|
||||||
|
|
||||||
playerRef.current = player;
|
playerRef.current = player;
|
||||||
}, playerReadyDependencyList); // eslint-disable-line
|
}, playerReadyDependencyList); // eslint-disable-line
|
||||||
|
|
Loading…
Reference in a new issue