Skip to content

Commit

Permalink
fix: fixed priority to be one-way
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Dec 22, 2022
1 parent 47d52d8 commit 85dc1f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/brave-hounds-divide.md
@@ -0,0 +1,7 @@
---
'@livepeer/core-react': patch
'@livepeer/react': patch
'@livepeer/react-native': patch
---

**Fix:** fixed `priority` boolean to not reset when video is not shown on screen.
14 changes: 8 additions & 6 deletions packages/core-react/src/components/player/Player.tsx
Expand Up @@ -130,6 +130,7 @@ export const usePlayer = <TElement, TPoster>(
{ _isCurrentlyShown }: InternalPlayerProps,
) => {
const [mediaElement, setMediaElement] = React.useState<TElement | null>(null);
const [loaded, setLoaded] = React.useState(false);

const { source, uploadStatus } = useSourceMimeTyped({
src,
Expand All @@ -139,11 +140,12 @@ export const usePlayer = <TElement, TPoster>(
autoUrlUpload,
});

// if the source is not priority or currently shown on the screen, then do not load
const sourceShouldBeLoaded = React.useMemo(
() => priority || _isCurrentlyShown,
[priority, _isCurrentlyShown],
);
// if the source is priority or currently shown on the screen, then load
React.useEffect(() => {
if (!loaded && (priority || _isCurrentlyShown)) {
setLoaded(true);
}
}, [priority, _isCurrentlyShown, loaded]);

const hidePosterOnPlayed = React.useMemo(
() =>
Expand Down Expand Up @@ -180,7 +182,7 @@ export const usePlayer = <TElement, TPoster>(

return {
mediaElement,
source: sourceShouldBeLoaded ? source : null,
source: loaded ? source : null,
uploadStatus,
playerProps: {
ref: playerRef,
Expand Down

3 comments on commit 85dc1f7

@vercel
Copy link

@vercel vercel bot commented on 85dc1f7 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 85dc1f7 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 85dc1f7 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.