running but needs some testing
This commit is contained in:
parent
be4b8a4631
commit
b7e55296d5
3 changed files with 41 additions and 36 deletions
|
@ -9,27 +9,28 @@ const TAP = {
|
||||||
RETRY: 'RETRY',
|
RETRY: 'RETRY',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ({ tapToUnmuteRef, tapToRetryRef, setReload, }) => {
|
const setLabel = (controlBar, childName, label) => {
|
||||||
|
const c = controlBar.getChild(childName);
|
||||||
|
if (c) {
|
||||||
|
c.controlText(label);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ({ tapToUnmuteRef, tapToRetryRef, setReload, videoTheaterMode,
|
||||||
|
playerRef, autoplaySetting}) => {
|
||||||
|
// 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) {
|
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 setLabel = (controlBar, childName, label) => {
|
|
||||||
const c = controlBar.getChild(childName);
|
|
||||||
if (c) {
|
|
||||||
c.controlText(label);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const player = playerRef.current;
|
const player = playerRef.current;
|
||||||
if (player) {
|
if (player) {
|
||||||
const ctrlBar = player.getChild('controlBar');
|
const ctrlBar = player.getChild('controlBar');
|
||||||
|
@ -121,7 +122,7 @@ export default ({ tapToUnmuteRef, tapToRetryRef, setReload, }) => {
|
||||||
}
|
}
|
||||||
}, [videoTheaterMode]);
|
}, [videoTheaterMode]);
|
||||||
|
|
||||||
|
// when user clicks 'Unmute' button, turn audio on and hide unmute button
|
||||||
function unmuteAndHideHint() {
|
function unmuteAndHideHint() {
|
||||||
const player = playerRef.current;
|
const player = playerRef.current;
|
||||||
if (player) {
|
if (player) {
|
||||||
|
@ -154,7 +155,7 @@ export default ({ tapToUnmuteRef, tapToRetryRef, setReload, }) => {
|
||||||
|
|
||||||
switch (tapButton) {
|
switch (tapButton) {
|
||||||
case TAP.NONE:
|
case TAP.NONE:
|
||||||
setButtonVisibility(/*tapToUnmuteRef*/, false);
|
setButtonVisibility(tapToUnmuteRef, false);
|
||||||
setButtonVisibility(tapToRetryRef, false);
|
setButtonVisibility(tapToRetryRef, false);
|
||||||
break;
|
break;
|
||||||
case TAP.UNMUTE:
|
case TAP.UNMUTE:
|
||||||
|
@ -171,8 +172,9 @@ export default ({ tapToUnmuteRef, tapToRetryRef, setReload, }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('RUNNING HERE!')
|
||||||
|
|
||||||
const player = playerRef.current;
|
const player = playerRef.current;
|
||||||
if (player) {
|
if (player) {
|
||||||
const touchOverlay = player.getChild('TouchOverlay');
|
const touchOverlay = player.getChild('TouchOverlay');
|
||||||
|
@ -189,7 +191,6 @@ export default ({ tapToUnmuteRef, tapToRetryRef, setReload, }) => {
|
||||||
}
|
}
|
||||||
}, [autoplaySetting]);
|
}, [autoplaySetting]);
|
||||||
|
|
||||||
|
|
||||||
// Add various event listeners to player
|
// Add various event listeners to player
|
||||||
player.one('play', onInitialPlay);
|
player.one('play', onInitialPlay);
|
||||||
player.on('play', resolveCtrlText);
|
player.on('play', resolveCtrlText);
|
||||||
|
@ -199,11 +200,10 @@ export default ({ tapToUnmuteRef, tapToRetryRef, setReload, }) => {
|
||||||
player.on('volumechange', resolveCtrlText);
|
player.on('volumechange', resolveCtrlText);
|
||||||
player.on('volumechange', onVolumeChange);
|
player.on('volumechange', onVolumeChange);
|
||||||
player.on('error', onError);
|
player.on('error', onError);
|
||||||
player.on('ended', onEnded);
|
// player.on('ended', onEnded);
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
detectFileType,
|
retryVideoAfterFailure,
|
||||||
createVideoPlayerDOM,
|
unmuteAndHideHint,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
export default ({ source, sourceType, videoJsOptions, isAudio }) => {
|
export default ({ source, sourceType, videoJsOptions, isAudio }) => {
|
||||||
|
|
||||||
function detectFileType() {
|
function detectFileType() {
|
||||||
|
|
|
@ -135,13 +135,6 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
playPrevious,
|
playPrevious,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
// initiate keyboard shortcuts
|
|
||||||
const { curried_function } = keyboardShorcuts({ toggleVideoTheaterMode, playNext, playPrevious });
|
|
||||||
|
|
||||||
const [reload, setReload] = useState('initial');
|
|
||||||
|
|
||||||
const { initializeEvents, unmuteAndHideHint, retryVideoAfterFailure } = events(videoTheaterMode, setReload, autoplaySetting);
|
|
||||||
|
|
||||||
// will later store the videojs player
|
// will later store the videojs player
|
||||||
const playerRef = useRef();
|
const playerRef = useRef();
|
||||||
const containerRef = useRef();
|
const containerRef = useRef();
|
||||||
|
@ -149,6 +142,11 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
const tapToUnmuteRef = useRef();
|
const tapToUnmuteRef = useRef();
|
||||||
const tapToRetryRef = useRef();
|
const tapToRetryRef = useRef();
|
||||||
|
|
||||||
|
// initiate keyboard shortcuts
|
||||||
|
const { curried_function } = keyboardShorcuts({ toggleVideoTheaterMode, playNext, playPrevious });
|
||||||
|
|
||||||
|
const [reload, setReload] = useState('initial');
|
||||||
|
|
||||||
const videoJsOptions = {
|
const videoJsOptions = {
|
||||||
...VIDEO_JS_OPTIONS,
|
...VIDEO_JS_OPTIONS,
|
||||||
autoplay: autoplay,
|
autoplay: autoplay,
|
||||||
|
@ -173,6 +171,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
|
|
||||||
const { detectFileType, createVideoPlayerDOM } = functions({ source, sourceType, videoJsOptions, isAudio });
|
const { detectFileType, createVideoPlayerDOM } = functions({ source, sourceType, videoJsOptions, isAudio });
|
||||||
|
|
||||||
|
let unmuteAndHideHint, retryVideoAfterFailure;
|
||||||
// Initialize video.js
|
// Initialize video.js
|
||||||
function initializeVideoPlayer(el) {
|
function initializeVideoPlayer(el) {
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
|
@ -185,7 +184,12 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
|
|
||||||
runAds(internalFeatureEnabled, allowPreRoll, player);
|
runAds(internalFeatureEnabled, allowPreRoll, player);
|
||||||
|
|
||||||
initializeEvents({ player, tapToRetryRef, tapToUnmuteRef });
|
const videoJsEvents = events({ tapToUnmuteRef, tapToRetryRef, setReload, videoTheaterMode, playerRef, autoplaySetting, player });
|
||||||
|
|
||||||
|
unmuteAndHideHint = { events };
|
||||||
|
retryVideoAfterFailure = { events };
|
||||||
|
|
||||||
|
videoJsEvents.initializeEvents({ player, tapToRetryRef, tapToUnmuteRef });
|
||||||
|
|
||||||
// Replace volume bar with custom LBRY volume bar
|
// Replace volume bar with custom LBRY volume bar
|
||||||
LbryVolumeBarClass.replaceExisting(player);
|
LbryVolumeBarClass.replaceExisting(player);
|
||||||
|
|
Loading…
Reference in a new issue