Skip to content

Commit

Permalink
Merge pull request #40068 from nkdengineer/fix/39253
Browse files Browse the repository at this point in the history
fix: Video - Console error shows up when playing video
  • Loading branch information
luacmartins authored Apr 15, 2024
2 parents 1cb6e00 + 89386b6 commit ad38df4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ function BaseVideoPlayer({
isVideoHovered = false,
}: VideoPlayerProps) {
const styles = useThemeStyles();
const {pauseVideo, playVideo, currentlyPlayingURL, sharedElement, originalParent, shareVideoPlayerElements, currentVideoPlayerRef, updateCurrentlyPlayingURL, videoResumeTryNumber} =
usePlaybackContext();
const {
pauseVideo,
playVideo,
currentlyPlayingURL,
sharedElement,
originalParent,
shareVideoPlayerElements,
currentVideoPlayerRef,
updateCurrentlyPlayingURL,
videoResumeTryNumber,
setCurrentlyPlayingURL,
} = usePlaybackContext();
const {isFullScreenRef} = useFullScreenContext();
const {isOffline} = useNetwork();
const [duration, setDuration] = useState(videoDuration * 1000);
Expand Down Expand Up @@ -181,6 +191,19 @@ function BaseVideoPlayer({
currentVideoPlayerRef.current = videoPlayerRef.current;
}, [url, currentVideoPlayerRef, isUploading]);

const isCurrentlyURLSetRef = useRef<boolean>();
isCurrentlyURLSetRef.current = isCurrentlyURLSet;

useEffect(
() => () => {
if (!isCurrentlyURLSetRef.current) {
return;
}

setCurrentlyPlayingURL(null);
},
[setCurrentlyPlayingURL],
);
// update shared video elements
useEffect(() => {
if (shouldUseSharedVideoElement || url !== currentlyPlayingURL || isFullScreenRef.current) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/VideoPlayerContexts/PlaybackContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ function PlaybackContextProvider({children}: ChildrenProps) {
sharedElement,
currentVideoPlayerRef,
shareVideoPlayerElements,
setCurrentlyPlayingURL,
playVideo,
pauseVideo,
checkVideoPlaying,
videoResumeTryNumber,
}),
[updateCurrentlyPlayingURL, currentlyPlayingURL, originalParent, sharedElement, shareVideoPlayerElements, playVideo, pauseVideo, checkVideoPlaying],
[updateCurrentlyPlayingURL, currentlyPlayingURL, originalParent, sharedElement, shareVideoPlayerElements, playVideo, pauseVideo, checkVideoPlaying, setCurrentlyPlayingURL],
);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type PlaybackContext = {
playVideo: () => void;
pauseVideo: () => void;
checkVideoPlaying: (statusCallback: StatusCallback) => void;
setCurrentlyPlayingURL: React.Dispatch<React.SetStateAction<string | null>>;
};

type VolumeContext = {
Expand Down

0 comments on commit ad38df4

Please sign in to comment.