Skip to content

Commit 0d152c3

Browse files
authored
Merge pull request #37674 from software-mansion-labs/@Skalakid/fix-resuming-video-after-regaining-internet-connection
Fix video not loading after regaining internet connection
2 parents d888ffc + 6e74315 commit 0d152c3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/components/VideoPlayer/BaseVideoPlayer.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Hoverable from '@components/Hoverable';
88
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
99
import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext';
1010
import VideoPopoverMenu from '@components/VideoPopoverMenu';
11+
import useNetwork from '@hooks/useNetwork';
1112
import useThemeStyles from '@hooks/useThemeStyles';
1213
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
1314
import * as Browser from '@libs/Browser';
@@ -45,6 +46,7 @@ function BaseVideoPlayer({
4546
const styles = useThemeStyles();
4647
const {pauseVideo, playVideo, currentlyPlayingURL, updateSharedElements, sharedElement, originalParent, shareVideoPlayerElements, currentVideoPlayerRef, updateCurrentlyPlayingURL} =
4748
usePlaybackContext();
49+
const {isOffline} = useNetwork();
4850
const [duration, setDuration] = useState(videoDuration * 1000);
4951
const [position, setPosition] = useState(0);
5052
const [isPlaying, setIsPlaying] = useState(false);
@@ -253,13 +255,20 @@ function BaseVideoPlayer({
253255
style={[styles.w100, styles.h100, videoPlayerStyle]}
254256
videoStyle={[styles.w100, styles.h100, videoStyle]}
255257
source={{
256-
uri: sourceURL,
258+
// if video is loading and is offline, we want to change uri to null to
259+
// reset the video player after connection is back
260+
uri: !isLoading || (isLoading && !isOffline) ? sourceURL : null,
257261
}}
258262
shouldPlay={false}
259263
useNativeControls={false}
260264
resizeMode={resizeMode}
261265
isLooping={isLooping}
262-
onReadyForDisplay={onVideoLoaded}
266+
onReadyForDisplay={(e) => {
267+
if (isCurrentlyURLSet && !isUploading) {
268+
playVideo();
269+
}
270+
onVideoLoaded(e);
271+
}}
263272
onPlaybackStatusUpdate={handlePlaybackStatusUpdate}
264273
onFullscreenUpdate={handleFullscreenUpdate}
265274
/>

0 commit comments

Comments
 (0)