Skip to content

Commit

Permalink
Merge pull request Expensify#36914 from tienifr/fix/36865
Browse files Browse the repository at this point in the history
fix: On full screen mode, when the video ends, the play button does nothing
  • Loading branch information
rlinoz authored Feb 22, 2024
2 parents 6adfbf2 + 372b082 commit 143d88b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
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;
}

0 comments on commit 143d88b

Please sign in to comment.