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

View file

@ -59,6 +59,7 @@ type Props = {
userId: ?number, userId: ?number,
// allowPreRoll: ?boolean, // allowPreRoll: ?boolean,
shareTelemetry: boolean, shareTelemetry: boolean,
replay: boolean,
}; };
// type VideoJSOptions = { // type VideoJSOptions = {
@ -197,6 +198,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
userId, userId,
// allowPreRoll, // allowPreRoll,
shareTelemetry, shareTelemetry,
replay,
} = props; } = props;
const [reload, setReload] = useState('initial'); const [reload, setReload] = useState('initial');
@ -601,6 +603,13 @@ export default React.memo<Props>(function VideoJs(props: Props) {
return vjs; 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. // This lifecycle hook is only called once (on mount), or when `isAudio` changes.
useEffect(() => { useEffect(() => {
const vjsElement = createVideoPlayerDOM(containerRef.current); 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 /* 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 */ breaks because some browsers (e.g. Firefox) block autoplay but leave the player.play Promise pending */
const [isLoading, setIsLoading] = useState(false); 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) // force everything to recent when URI changes, can cause weird corner cases otherwise (e.g. navigate while autoplay is true)
useEffect(() => { useEffect(() => {
@ -174,6 +175,7 @@ function VideoViewer(props: Props) {
setIsPlaying(true); setIsPlaying(true);
setShowAutoplayCountdown(false); setShowAutoplayCountdown(false);
setIsEndededEmbed(false); setIsEndededEmbed(false);
setReplay(false);
analytics.videoIsPlaying(true, player); analytics.videoIsPlaying(true, player);
} }
@ -285,7 +287,7 @@ function VideoViewer(props: Props) {
})} })}
onContextMenu={stopContextMenu} onContextMenu={stopContextMenu}
> >
{showAutoplayCountdown && <AutoplayCountdown uri={uri} />} {showAutoplayCountdown && <AutoplayCountdown uri={uri} setReplay={setReplay} />}
{isEndededEmbed && <FileViewerEmbeddedEnded uri={uri} />} {isEndededEmbed && <FileViewerEmbeddedEnded uri={uri} />}
{embedded && !isEndededEmbed && <FileViewerEmbeddedTitle uri={uri} />} {embedded && !isEndededEmbed && <FileViewerEmbeddedTitle uri={uri} />}
{/* disable this loading behavior because it breaks when player.play() promise hangs */} {/* disable this loading behavior because it breaks when player.play() promise hangs */}
@ -336,6 +338,7 @@ function VideoViewer(props: Props) {
userId={userId} userId={userId}
allowPreRoll={!embedded && !authenticated} allowPreRoll={!embedded && !authenticated}
shareTelemetry={shareTelemetry} shareTelemetry={shareTelemetry}
replay={replay}
/> />
)} )}
</div> </div>