Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b62b5c3516 |
No files matched your search
@@ -151,8 +151,8 @@ const onPlayerReady = (player, options) => {
|
||||
* Never shows if the endscreen plugin is present
|
||||
*/
|
||||
const mobileUi = function(options) {
|
||||
// if (videojs.browser.IS_ANDROID || videojs.browser.IS_IOS) {
|
||||
if (videojs.browser.IS_ANDROID) {
|
||||
if (videojs.browser.IS_ANDROID || videojs.browser.IS_IOS) {
|
||||
// if (videojs.browser.IS_ANDROID) {
|
||||
this.ready(() => {
|
||||
onPlayerReady(this, videojs.mergeOptions(defaults, options));
|
||||
});
|
||||
|
||||
@@ -59,6 +59,7 @@ type Props = {
|
||||
userId: ?number,
|
||||
// allowPreRoll: ?boolean,
|
||||
shareTelemetry: boolean,
|
||||
showAutoplayCountdown: boolean
|
||||
};
|
||||
|
||||
// type VideoJSOptions = {
|
||||
@@ -84,11 +85,12 @@ const VIDEO_JS_OPTIONS = {
|
||||
controls: true,
|
||||
html5: {
|
||||
vhs: {
|
||||
overrideNative: !videojs.browser.IS_ANY_SAFARI,
|
||||
overrideNative: true, // don't override on safari
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// keys to bind to for keyboard shortcuts
|
||||
const SPACE_BAR_KEYCODE = 32;
|
||||
const SMALL_F_KEYCODE = 70;
|
||||
const SMALL_M_KEYCODE = 77;
|
||||
@@ -103,19 +105,6 @@ const SMALL_J_KEYCODE = 74;
|
||||
const SMALL_K_KEYCODE = 75;
|
||||
const SMALL_L_KEYCODE = 76;
|
||||
|
||||
const numberCodes = {
|
||||
'48': 0,
|
||||
'49': 1,
|
||||
'50': 2,
|
||||
'51': 3,
|
||||
'52': 4,
|
||||
'53': 5,
|
||||
'54': 6,
|
||||
'55': 7,
|
||||
'56': 8,
|
||||
'57': 9,
|
||||
};
|
||||
|
||||
const FULLSCREEN_KEYCODE = SMALL_F_KEYCODE;
|
||||
const MUTE_KEYCODE = SMALL_M_KEYCODE;
|
||||
const THEATER_MODE_KEYCODE = SMALL_T_KEYCODE;
|
||||
@@ -131,6 +120,7 @@ const SEEK_BACKWARD_KEYCODE_5 = ARROW_LEFT_KEYCODE;
|
||||
const SEEK_STEP_5 = 5;
|
||||
const SEEK_STEP = 10; // time to seek in seconds
|
||||
|
||||
// register videojs plugins
|
||||
if (!Object.keys(videojs.getPlugins()).includes('eventTracking')) {
|
||||
videojs.registerPlugin('eventTracking', eventTracking);
|
||||
}
|
||||
@@ -210,6 +200,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
userId,
|
||||
// allowPreRoll,
|
||||
shareTelemetry,
|
||||
showAutoplayCountdown,
|
||||
} = props;
|
||||
|
||||
const [reload, setReload] = useState('initial');
|
||||
@@ -230,11 +221,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
eventTracking: true,
|
||||
overlay: OVERLAY.OVERLAY_DATA,
|
||||
},
|
||||
// fixes problem of errant CC button showing up on iOS
|
||||
// the true fix here is to fix the m3u8 file, see: https://github.com/lbryio/lbry-desktop/pull/6315
|
||||
controlBar: {
|
||||
subsCapsButton: false,
|
||||
},
|
||||
// bigPlayButton: false,
|
||||
};
|
||||
|
||||
const tapToUnmuteRef = useRef();
|
||||
@@ -259,6 +246,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
|
||||
switch (tapButton) {
|
||||
case TAP.NONE:
|
||||
document.getElementsByClassName('video-js--tap-to-unmute')[0].style.visibility = 'hidden';
|
||||
setButtonVisibility(tapToUnmuteRef, false);
|
||||
setButtonVisibility(tapToRetryRef, false);
|
||||
break;
|
||||
@@ -276,14 +264,18 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
}
|
||||
}
|
||||
|
||||
// unmute video when player hits "Tap to unmute button"
|
||||
function unmuteAndHideHint() {
|
||||
const player = playerRef.current;
|
||||
if (player) {
|
||||
// unmute the video
|
||||
player.muted(false);
|
||||
// turn the volume all the way up if it's at 0
|
||||
if (player.volume() === 0) {
|
||||
player.volume(1.0);
|
||||
}
|
||||
}
|
||||
// hide "Tap to unmute" button
|
||||
showTapButton(TAP.NONE);
|
||||
}
|
||||
|
||||
@@ -295,56 +287,54 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
}
|
||||
}
|
||||
|
||||
// Override the player's control text. We override to:
|
||||
// 1. Add keyboard shortcut to the tool-tip.
|
||||
// 2. Override videojs' i18n and use our own (don't want to have 2 systems).
|
||||
//
|
||||
// Notes:
|
||||
// - For dynamic controls (e.g. play/pause), those unfortunately need to be
|
||||
// updated again at their event-listener level (that's just the way videojs
|
||||
// updates the text), hence the need to listen to 'play', 'pause' and 'volumechange'
|
||||
// on top of just 'loadstart'.
|
||||
// - videojs changes the MuteToggle text at 'loadstart', so this was chosen
|
||||
// as the listener to update static texts.
|
||||
function resolveCtrlText(e, initialPlay) {
|
||||
function resolveCtrlText(e) {
|
||||
// Override the player's control text. We override to:
|
||||
// 1. Add keyboard shortcut to the tool-tip.
|
||||
// 2. Override videojs' i18n and use our own (don't want to have 2 systems).
|
||||
//
|
||||
// Notes:
|
||||
// - For dynamic controls (e.g. play/pause), those unfortunately need to be
|
||||
// updated again at their event-listener level (that's just the way videojs
|
||||
// updates the text), hence the need to listen to 'play', 'pause' and 'volumechange'
|
||||
// on top of just 'loadstart'.
|
||||
// - videojs changes the MuteToggle text at 'loadstart', so this was chosen
|
||||
// as the listener to update static texts.
|
||||
const player = playerRef.current;
|
||||
if (player) {
|
||||
const controlBar = player.getChild('controlBar');
|
||||
// const controlBar = player.getChild('controlBar');
|
||||
switch (e.type) {
|
||||
case 'play':
|
||||
controlBar.getChild('PlayToggle').controlText(__('Pause (space/k)'));
|
||||
if (initialPlay) {
|
||||
controlBar.getChild('PlaybackRateMenuButton').controlText(__('Playback Rate (<, >)'));
|
||||
controlBar.getChild('QualityButton').controlText(__('Quality'));
|
||||
resolveCtrlText({ type: 'fullscreenchange' });
|
||||
resolveCtrlText({ type: 'volumechange' });
|
||||
resolveCtrlText({ type: 'fullscreenchange' });
|
||||
// --- Do everything ---
|
||||
// (1) The 'Theater mode' button should probably be changed to a class
|
||||
// so that we can use getChild() with a specific name. There might be
|
||||
// clashes if we add a new button in the future.
|
||||
// (2) We'll have to get 'makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)'
|
||||
// as a prop here so we can say "Theater mode|Default mode" instead of
|
||||
// "Toggle Theater mode".
|
||||
controlBar.getChild('Button').controlText(__('Toggle Theater mode (t)'));
|
||||
}
|
||||
// controlBar.getChild('PlayToggle').controlText(__('Pause (space)'));
|
||||
break;
|
||||
case 'pause':
|
||||
controlBar.getChild('PlayToggle').controlText(__('Play (space/k)'));
|
||||
// controlBar.getChild('PlayToggle').controlText(__('Play (space)'));
|
||||
break;
|
||||
case 'volumechange':
|
||||
controlBar
|
||||
.getChild('VolumePanel')
|
||||
.getChild('MuteToggle')
|
||||
.controlText(player.muted() || player.volume() === 0 ? __('Unmute (m)') : __('Mute (m)'));
|
||||
// controlBar
|
||||
// .getChild('VolumePanel')
|
||||
// .getChild('MuteToggle')
|
||||
// .controlText(player.muted() || player.volume() === 0 ? __('Unmute (m)') : __('Mute (m)'));
|
||||
break;
|
||||
case 'fullscreenchange':
|
||||
controlBar
|
||||
.getChild('FullscreenToggle')
|
||||
.controlText(player.isFullscreen() ? __('Exit Fullscreen (f)') : __('Fullscreen (f)'));
|
||||
// controlBar
|
||||
// .getChild('FullscreenToggle')
|
||||
// .controlText(player.isFullscreen() ? __('Exit Fullscreen (f)') : __('Fullscreen (f)'));
|
||||
break;
|
||||
case 'loadstart':
|
||||
resolveCtrlText({ type: 'play' }, true);
|
||||
// --- Do everything ---
|
||||
// controlBar.getChild('PlaybackRateMenuButton').controlText(__('Playback Rate (<, >)'));
|
||||
// controlBar.getChild('QualityButton').controlText(__('Quality'));
|
||||
resolveCtrlText({ type: 'play' });
|
||||
resolveCtrlText({ type: 'pause' });
|
||||
resolveCtrlText({ type: 'volumechange' });
|
||||
resolveCtrlText({ type: 'fullscreenchange' });
|
||||
// (1) The 'Theater mode' button should probably be changed to a class
|
||||
// so that we can use getChild() with a specific name. There might be
|
||||
// clashes if we add a new button in the future.
|
||||
// (2) We'll have to get 'makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)'
|
||||
// as a prop here so we can say "Theater mode|Default mode" instead of
|
||||
// "Toggle Theater mode".
|
||||
// controlBar.getChild('Button').controlText(__('Toggle Theater mode (t)'));
|
||||
break;
|
||||
default:
|
||||
if (isDev) throw Error('Unexpected: ' + e.type);
|
||||
@@ -355,6 +345,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
|
||||
function onInitialPlay() {
|
||||
const player = playerRef.current;
|
||||
// show the unmute button if the video is muted
|
||||
if (player && (player.muted() || player.volume() === 0)) {
|
||||
// The css starts as "hidden". We make it visible here without
|
||||
// re-rendering the whole thing.
|
||||
@@ -362,7 +353,6 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
} else {
|
||||
showTapButton(TAP.NONE);
|
||||
}
|
||||
resolveCtrlText({ type: 'play' }, true);
|
||||
}
|
||||
|
||||
function onVolumeChange() {
|
||||
@@ -373,6 +363,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
}
|
||||
|
||||
function onError() {
|
||||
console.log('error!');
|
||||
const player = playerRef.current;
|
||||
showTapButton(TAP.RETRY);
|
||||
|
||||
@@ -413,28 +404,19 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
if (e.keyCode === VOLUME_UP_KEYCODE) volumeUp();
|
||||
if (e.keyCode === VOLUME_DOWN_KEYCODE) volumeDown();
|
||||
if (e.keyCode === THEATER_MODE_KEYCODE) toggleTheaterMode();
|
||||
if (e.keyCode === SEEK_FORWARD_KEYCODE) seekVideo(SEEK_STEP, false);
|
||||
if (e.keyCode === SEEK_BACKWARD_KEYCODE) seekVideo(-SEEK_STEP, false);
|
||||
if (e.keyCode === SEEK_FORWARD_KEYCODE_5) seekVideo(SEEK_STEP_5, false);
|
||||
if (e.keyCode === SEEK_BACKWARD_KEYCODE_5) seekVideo(-SEEK_STEP_5, false);
|
||||
if (String(e.keyCode) in numberCodes) seekVideo(numberCodes[String(e.keyCode)], true);
|
||||
if (e.keyCode === SEEK_FORWARD_KEYCODE) seekVideo(SEEK_STEP);
|
||||
if (e.keyCode === SEEK_BACKWARD_KEYCODE) seekVideo(-SEEK_STEP);
|
||||
if (e.keyCode === SEEK_FORWARD_KEYCODE_5) seekVideo(SEEK_STEP_5);
|
||||
if (e.keyCode === SEEK_BACKWARD_KEYCODE_5) seekVideo(-SEEK_STEP_5);
|
||||
}
|
||||
|
||||
function seekVideo(stepSize: number, numberedStep: boolean) {
|
||||
function seekVideo(stepSize: number) {
|
||||
const player = playerRef.current;
|
||||
const videoNode = containerRef.current && containerRef.current.querySelector('video, audio');
|
||||
if (!videoNode || !player) return;
|
||||
const duration = videoNode.duration;
|
||||
const numberedStepSize = duration / 10;
|
||||
const currentTime = videoNode.currentTime;
|
||||
|
||||
let newDuration;
|
||||
if (numberedStep) {
|
||||
newDuration = numberedStepSize * stepSize;
|
||||
} else {
|
||||
newDuration = currentTime + stepSize;
|
||||
}
|
||||
|
||||
const newDuration = currentTime + stepSize;
|
||||
if (newDuration < 0) {
|
||||
videoNode.currentTime = 0;
|
||||
} else if (newDuration > duration) {
|
||||
@@ -442,8 +424,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
} else {
|
||||
videoNode.currentTime = newDuration;
|
||||
}
|
||||
|
||||
if (!numberedStep) OVERLAY.showSeekedOverlay(player, Math.abs(stepSize), stepSize > 0);
|
||||
OVERLAY.showSeekedOverlay(player, Math.abs(stepSize), stepSize > 0);
|
||||
player.userActive(true);
|
||||
}
|
||||
|
||||
@@ -518,7 +499,8 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.setAttribute('data-vjs-player', 'true');
|
||||
const el = document.createElement(isAudio ? 'audio' : 'video');
|
||||
el.className = 'video-js vjs-big-play-centered ';
|
||||
el.className = 'video-js vjs-big-play-centered';
|
||||
|
||||
wrapper.appendChild(el);
|
||||
|
||||
container.appendChild(wrapper);
|
||||
@@ -651,10 +633,11 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
window.removeEventListener('keydown', handleKeyDown);
|
||||
|
||||
const player = playerRef.current;
|
||||
if (player) {
|
||||
player.dispose();
|
||||
window.player = undefined;
|
||||
}
|
||||
player.pause()
|
||||
player.dispose();
|
||||
window.oldPlayer = window.player;
|
||||
window.player = undefined;
|
||||
|
||||
};
|
||||
}, [isAudio]);
|
||||
|
||||
@@ -692,6 +675,8 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
});
|
||||
}, [source, reload]);
|
||||
|
||||
console.log('RUNNING HERE VIDEOJS!');
|
||||
|
||||
return (
|
||||
// $FlowFixMe
|
||||
<div className={classnames('video-js-parent', { 'video-js-parent--ios': IS_IOS })} ref={containerRef}>
|
||||
|
||||
@@ -109,6 +109,13 @@ function VideoViewer(props: Props) {
|
||||
breaks because some browsers (e.g. Firefox) block autoplay but leave the player.play Promise pending */
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const IS_IOS =
|
||||
(/iPad|iPhone|iPod/.test(navigator.platform) ||
|
||||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
|
||||
!window.MSStream;
|
||||
|
||||
console.log("RUNNING HERE PARENT VIEW.")
|
||||
|
||||
// force everything to recent when URI changes, can cause weird corner cases otherwise (e.g. navigate while autoplay is true)
|
||||
useEffect(() => {
|
||||
if (uri && previousUri && uri !== previousUri) {
|
||||
@@ -203,7 +210,17 @@ function VideoViewer(props: Props) {
|
||||
playerReadyDependencyList.push(desktopPlayStartTime);
|
||||
}
|
||||
|
||||
let alreadyRunning = false;
|
||||
|
||||
const onPlayerReady = useCallback((player: Player) => {
|
||||
console.log('already running');
|
||||
console.log(alreadyRunning)
|
||||
console.log(new Date())
|
||||
alreadyRunning = true;
|
||||
|
||||
|
||||
console.log("PLAYER READY CALLBACK")
|
||||
|
||||
if (!embedded) {
|
||||
player.muted(muted);
|
||||
player.volume(volume);
|
||||
@@ -212,23 +229,52 @@ function VideoViewer(props: Props) {
|
||||
}
|
||||
|
||||
const shouldPlay = !embedded || autoplayIfEmbedded;
|
||||
|
||||
// console.log('should play');
|
||||
// console.log(shouldPlay);
|
||||
|
||||
// TODO: this is causing issues with videos starting randomly
|
||||
// https://blog.videojs.com/autoplay-best-practices-with-video-js/#Programmatic-Autoplay-and-Success-Failure-Detection
|
||||
if (shouldPlay) {
|
||||
const playPromise = player.play();
|
||||
const timeoutPromise = new Promise((resolve, reject) =>
|
||||
setTimeout(() => reject(PLAY_TIMEOUT_ERROR), PLAY_TIMEOUT_LIMIT)
|
||||
);
|
||||
console.log('starting video!');
|
||||
|
||||
Promise.race([playPromise, timeoutPromise]).catch((error) => {
|
||||
if (typeof error === 'object' && error.name && error.name === 'NotAllowedError') {
|
||||
if (player.autoplay() && !player.muted()) {
|
||||
// player.muted(true);
|
||||
// another version had player.play()
|
||||
(async function() {
|
||||
try {
|
||||
console.log('is playing already');
|
||||
console.log(isPlaying);
|
||||
console.log('player');
|
||||
console.log(player);
|
||||
// console.log('is paused!');
|
||||
// console.log(player.paused());
|
||||
|
||||
const isAlreadyPlaying = isPlaying;
|
||||
setIsPlaying(true);
|
||||
|
||||
if (!isAlreadyPlaying) {
|
||||
console.log('STARTING PLAYER')
|
||||
const playerResponse = player.play();
|
||||
const isPaused = player.paused();
|
||||
// console.log(playerResponse)
|
||||
// await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
// console.log(playerResponse);
|
||||
if (IS_IOS && isPaused) {
|
||||
document.getElementsByClassName('video-js--tap-to-unmute')[0].style.visibility = 'visible';
|
||||
player.muted(true);
|
||||
const iosResponse = player.play();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
console.log(iosResponse);
|
||||
}
|
||||
} else {
|
||||
console.log('ALREADY HAVE PLAYER, DISPOSING!!')
|
||||
player.dispose()
|
||||
}
|
||||
console.log('\n\n')
|
||||
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
setIsLoading(false);
|
||||
setIsPlaying(false);
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
setIsLoading(shouldPlay); // if we are here outside of an embed, we're playing
|
||||
@@ -261,6 +307,7 @@ function VideoViewer(props: Props) {
|
||||
changeMute(player.muted());
|
||||
}
|
||||
});
|
||||
|
||||
player.on('ratechange', () => {
|
||||
const HAVE_NOTHING = 0; // https://docs.videojs.com/player#readyState
|
||||
if (player && player.readyState() !== HAVE_NOTHING) {
|
||||
@@ -289,7 +336,7 @@ function VideoViewer(props: Props) {
|
||||
{isEndededEmbed && <FileViewerEmbeddedEnded uri={uri} />}
|
||||
{embedded && !isEndededEmbed && <FileViewerEmbeddedTitle uri={uri} />}
|
||||
{/* disable this loading behavior because it breaks when player.play() promise hangs */}
|
||||
{isLoading && <LoadingScreen status={__('Loading')} />}
|
||||
{/* {isLoading && <LoadingScreen status={__('Loading')} />} */}
|
||||
|
||||
{!isFetchingAd && adUrl && (
|
||||
<>
|
||||
@@ -336,6 +383,7 @@ function VideoViewer(props: Props) {
|
||||
userId={userId}
|
||||
allowPreRoll={!embedded && !authenticated}
|
||||
shareTelemetry={shareTelemetry}
|
||||
showAutoplayCountdown={autoplaySetting}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -150,3 +150,10 @@
|
||||
.bottom-gradient {
|
||||
background-image: linear-gradient(to top, rgba(0, 0, 0, 0.4) 0%, transparent 72px);
|
||||
}
|
||||
|
||||
.vjs-big-play-button {
|
||||
// if the user is using a mouse
|
||||
@media (pointer: none), (pointer:coarse) {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user