Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/VideoPlayer/BaseVideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import * as Browser from '@libs/Browser';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import {videoPlayerDefaultProps, videoPlayerPropTypes} from './propTypes';
import shouldReplayVideo from './shouldReplayVideo';
import VideoPlayerControls from './VideoPlayerControls';

const isMobileSafari = Browser.isMobileSafari();
Expand Down Expand Up @@ -95,6 +96,9 @@ function BaseVideoPlayer({

const handlePlaybackStatusUpdate = useCallback(
(e) => {
if (shouldReplayVideo(e, isPlaying, duration, position)) {
videoPlayerRef.current.setStatusAsync({positionMillis: 0, shouldPlay: true});
}
const isVideoPlaying = e.isPlaying || false;
preventPausingWhenExitingFullscreen(isVideoPlaying);
setIsPlaying(isVideoPlaying);
Expand All @@ -105,7 +109,7 @@ function BaseVideoPlayer({

onPlaybackStatusUpdate(e);
},
[onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration],
[onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration, isPlaying, duration, position],
);

const handleFullscreenUpdate = useCallback(
Expand Down
11 changes: 11 additions & 0 deletions src/components/VideoPlayer/shouldReplayVideo.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type {AVPlaybackStatusSuccess} from 'expo-av';

/**
* Whether to replay the video when users press play button
*/
export default function shouldReplayVideo(e: AVPlaybackStatusSuccess, isPlaying: boolean, duration: number, position: number): boolean {
if (!isPlaying && !e.didJustFinish && duration === position) {
return true;
}
return false;
}
11 changes: 11 additions & 0 deletions src/components/VideoPlayer/shouldReplayVideo.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type {AVPlaybackStatusSuccess} from 'expo-av';

/**
* Whether to replay the video when users press play button
*/
export default function shouldReplayVideo(e: AVPlaybackStatusSuccess, isPlaying: boolean, duration: number, position: number): boolean {
if (!isPlaying && e.isPlaying && duration === position) {
return true;
}
return false;
}
9 changes: 9 additions & 0 deletions src/components/VideoPlayer/shouldReplayVideo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {AVPlaybackStatusSuccess} from 'expo-av';

/**
* Whether to replay the video when users press play button
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default function shouldReplayVideo(e: AVPlaybackStatusSuccess, isPlaying: boolean, duration: number, position: number): boolean {
return false;
}