Add Replay Option to autoplayCountdown

This commit is contained in:
saltrafael 2021-08-20 07:28:38 -03:00 committed by zeppi
parent bc930ac13b
commit 7b70db4ea7
3 changed files with 26 additions and 1 deletions

View file

@ -7,6 +7,8 @@ import { formatLbryUrlForWeb } from 'util/url';
import { withRouter } from 'react-router';
import debounce from 'util/debounce';
import { COLLECTIONS_CONSTS } from 'lbry-redux';
import * as ICONS from 'constants/icons';
const DEBOUNCE_SCROLL_HANDLER_MS = 150;
const CLASSNAME_AUTOPLAY_COUNTDOWN = 'autoplay-countdown';
@ -19,6 +21,7 @@ type Props = {
doPlayUri: (string) => void,
modal: { id: string, modalProps: {} },
collectionId?: string,
setReplay: (boolean) => void,
};
function AutoplayCountdown(props: Props) {
@ -31,6 +34,7 @@ function AutoplayCountdown(props: Props) {
history: { push },
modal,
collectionId,
setReplay,
} = props;
const nextTitle = nextRecommendedClaim && nextRecommendedClaim.value && nextRecommendedClaim.value.title;
@ -142,6 +146,15 @@ function AutoplayCountdown(props: Props) {
<Button label={__('Cancel')} button="link" onClick={() => setTimerCanceled(true)} />
</div>
)}
<Button
label={__('Replay?')}
button="link"
iconRight={ICONS.REPLAY}
onClick={() => {
setTimerCanceled(true);
setReplay(true);
}}
/>
</div>
</div>
</div>

View file

@ -59,6 +59,7 @@ type Props = {
userId: ?number,
// allowPreRoll: ?boolean,
shareTelemetry: boolean,
replay: boolean,
};
// type VideoJSOptions = {
@ -197,6 +198,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
userId,
// allowPreRoll,
shareTelemetry,
replay,
} = props;
const [reload, setReload] = useState('initial');
@ -601,6 +603,13 @@ export default React.memo<Props>(function VideoJs(props: Props) {
return vjs;
}
useEffect(() => {
const player = playerRef.current;
if (replay && player) {
player.play();
}
}, [replay]);
// This lifecycle hook is only called once (on mount), or when `isAudio` changes.
useEffect(() => {
const vjsElement = createVideoPlayerDOM(containerRef.current);

View file

@ -108,6 +108,7 @@ function VideoViewer(props: Props) {
/* isLoading was designed to show loading screen on first play press, rather than completely black screen, but
breaks because some browsers (e.g. Firefox) block autoplay but leave the player.play Promise pending */
const [isLoading, setIsLoading] = useState(false);
const [replay, setReplay] = useState(false);
// force everything to recent when URI changes, can cause weird corner cases otherwise (e.g. navigate while autoplay is true)
useEffect(() => {
@ -174,6 +175,7 @@ function VideoViewer(props: Props) {
setIsPlaying(true);
setShowAutoplayCountdown(false);
setIsEndededEmbed(false);
setReplay(false);
analytics.videoIsPlaying(true, player);
}
@ -285,7 +287,7 @@ function VideoViewer(props: Props) {
})}
onContextMenu={stopContextMenu}
>
{showAutoplayCountdown && <AutoplayCountdown uri={uri} />}
{showAutoplayCountdown && <AutoplayCountdown uri={uri} setReplay={setReplay} />}
{isEndededEmbed && <FileViewerEmbeddedEnded uri={uri} />}
{embedded && !isEndededEmbed && <FileViewerEmbeddedTitle uri={uri} />}
{/* disable this loading behavior because it breaks when player.play() promise hangs */}
@ -336,6 +338,7 @@ function VideoViewer(props: Props) {
userId={userId}
allowPreRoll={!embedded && !authenticated}
shareTelemetry={shareTelemetry}
replay={replay}
/>
)}
</div>