From b6b77de1bfd8ba8a58b5f8eae257cca60fc58ab4 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 20 Feb 2024 22:46:57 +0700 Subject: [PATCH 1/3] fix: On full screen mode, when the video ends, the play button does nothing --- src/components/VideoPlayer/BaseVideoPlayer.js | 6 +++++- .../VideoPlayer/shouldReplayVideo.android.js | 15 +++++++++++++++ .../VideoPlayer/shouldReplayVideo.ios.js | 15 +++++++++++++++ src/components/VideoPlayer/shouldReplayVideo.js | 13 +++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/components/VideoPlayer/shouldReplayVideo.android.js create mode 100644 src/components/VideoPlayer/shouldReplayVideo.ios.js create mode 100644 src/components/VideoPlayer/shouldReplayVideo.js diff --git a/src/components/VideoPlayer/BaseVideoPlayer.js b/src/components/VideoPlayer/BaseVideoPlayer.js index 73dbf8407c0c..df79c7ef18da 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.js +++ b/src/components/VideoPlayer/BaseVideoPlayer.js @@ -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(); @@ -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); @@ -105,7 +109,7 @@ function BaseVideoPlayer({ onPlaybackStatusUpdate(e); }, - [onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration], + [onPlaybackStatusUpdate, preventPausingWhenExitingFullscreen, videoDuration, isPlaying, duration, position], ); const handleFullscreenUpdate = useCallback( diff --git a/src/components/VideoPlayer/shouldReplayVideo.android.js b/src/components/VideoPlayer/shouldReplayVideo.android.js new file mode 100644 index 000000000000..3b64b0059150 --- /dev/null +++ b/src/components/VideoPlayer/shouldReplayVideo.android.js @@ -0,0 +1,15 @@ +/** + * Whether to replay the video when users press play button + * + * @param {Object} e // playback status event + * @param {Boolean} isPlaying + * @param {Number} duration + * @param {Number} position + * @returns {Boolean} + */ +export default function shouldReplayVideo(e, isPlaying, duration, position) { + if (!isPlaying && !e.didJustFinish && duration === position) { + return true; + } + return false; +} diff --git a/src/components/VideoPlayer/shouldReplayVideo.ios.js b/src/components/VideoPlayer/shouldReplayVideo.ios.js new file mode 100644 index 000000000000..e60743d07a24 --- /dev/null +++ b/src/components/VideoPlayer/shouldReplayVideo.ios.js @@ -0,0 +1,15 @@ +/** + * Whether to replay the video when users press play button + * + * @param {Object} e // playback status event + * @param {Boolean} isPlaying + * @param {Number} duration + * @param {Number} position + * @returns {Boolean} + */ +export default function shouldReplayVideo(e, isPlaying, duration, position) { + if (!isPlaying && e.isPlaying && duration === position) { + return true; + } + return false; +} diff --git a/src/components/VideoPlayer/shouldReplayVideo.js b/src/components/VideoPlayer/shouldReplayVideo.js new file mode 100644 index 000000000000..b8716be952c6 --- /dev/null +++ b/src/components/VideoPlayer/shouldReplayVideo.js @@ -0,0 +1,13 @@ +/** + * Whether to replay the video when users press play button + * + * @param {Object} e // playback status event + * @param {Boolean} isPlaying // current isPlaying status + * @param {Number} duration + * @param {Number} position + * @returns {Boolean} + */ +// eslint-disable-next-line no-unused-vars +export default function shouldReplayVideo(e, isPlaying, duration, position) { + return false; +} From 178e1f612501a0b9a7cb15ff3be596898b297b06 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 20 Feb 2024 22:57:02 +0700 Subject: [PATCH 2/3] change to ts --- .../VideoPlayer/shouldReplayVideo.android.js | 15 --------------- .../VideoPlayer/shouldReplayVideo.android.ts | 11 +++++++++++ .../VideoPlayer/shouldReplayVideo.ios.js | 15 --------------- .../VideoPlayer/shouldReplayVideo.ios.ts | 11 +++++++++++ src/components/VideoPlayer/shouldReplayVideo.js | 13 ------------- src/components/VideoPlayer/shouldReplayVideo.ts | 9 +++++++++ 6 files changed, 31 insertions(+), 43 deletions(-) delete mode 100644 src/components/VideoPlayer/shouldReplayVideo.android.js create mode 100644 src/components/VideoPlayer/shouldReplayVideo.android.ts delete mode 100644 src/components/VideoPlayer/shouldReplayVideo.ios.js create mode 100644 src/components/VideoPlayer/shouldReplayVideo.ios.ts delete mode 100644 src/components/VideoPlayer/shouldReplayVideo.js create mode 100644 src/components/VideoPlayer/shouldReplayVideo.ts diff --git a/src/components/VideoPlayer/shouldReplayVideo.android.js b/src/components/VideoPlayer/shouldReplayVideo.android.js deleted file mode 100644 index 3b64b0059150..000000000000 --- a/src/components/VideoPlayer/shouldReplayVideo.android.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Whether to replay the video when users press play button - * - * @param {Object} e // playback status event - * @param {Boolean} isPlaying - * @param {Number} duration - * @param {Number} position - * @returns {Boolean} - */ -export default function shouldReplayVideo(e, isPlaying, duration, position) { - if (!isPlaying && !e.didJustFinish && duration === position) { - return true; - } - return false; -} diff --git a/src/components/VideoPlayer/shouldReplayVideo.android.ts b/src/components/VideoPlayer/shouldReplayVideo.android.ts new file mode 100644 index 000000000000..c66a32f312e0 --- /dev/null +++ b/src/components/VideoPlayer/shouldReplayVideo.android.ts @@ -0,0 +1,11 @@ +import {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; +} diff --git a/src/components/VideoPlayer/shouldReplayVideo.ios.js b/src/components/VideoPlayer/shouldReplayVideo.ios.js deleted file mode 100644 index e60743d07a24..000000000000 --- a/src/components/VideoPlayer/shouldReplayVideo.ios.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Whether to replay the video when users press play button - * - * @param {Object} e // playback status event - * @param {Boolean} isPlaying - * @param {Number} duration - * @param {Number} position - * @returns {Boolean} - */ -export default function shouldReplayVideo(e, isPlaying, duration, position) { - if (!isPlaying && e.isPlaying && duration === position) { - return true; - } - return false; -} diff --git a/src/components/VideoPlayer/shouldReplayVideo.ios.ts b/src/components/VideoPlayer/shouldReplayVideo.ios.ts new file mode 100644 index 000000000000..f53f1e7eba4d --- /dev/null +++ b/src/components/VideoPlayer/shouldReplayVideo.ios.ts @@ -0,0 +1,11 @@ +import {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; +} diff --git a/src/components/VideoPlayer/shouldReplayVideo.js b/src/components/VideoPlayer/shouldReplayVideo.js deleted file mode 100644 index b8716be952c6..000000000000 --- a/src/components/VideoPlayer/shouldReplayVideo.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Whether to replay the video when users press play button - * - * @param {Object} e // playback status event - * @param {Boolean} isPlaying // current isPlaying status - * @param {Number} duration - * @param {Number} position - * @returns {Boolean} - */ -// eslint-disable-next-line no-unused-vars -export default function shouldReplayVideo(e, isPlaying, duration, position) { - return false; -} diff --git a/src/components/VideoPlayer/shouldReplayVideo.ts b/src/components/VideoPlayer/shouldReplayVideo.ts new file mode 100644 index 000000000000..0a6cccac98ed --- /dev/null +++ b/src/components/VideoPlayer/shouldReplayVideo.ts @@ -0,0 +1,9 @@ +import {AVPlaybackStatusSuccess} from 'expo-av'; + +/** + * Whether to replay the video when users press play button + */ +// eslint-disable-next-line no-unused-vars +export default function shouldReplayVideo(e: AVPlaybackStatusSuccess, isPlaying: boolean, duration: number, position: number): boolean { + return false; +} From 372b0820970cf5844d525f40c7a9d5335f777a24 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 20 Feb 2024 23:02:57 +0700 Subject: [PATCH 3/3] fix: lint --- src/components/VideoPlayer/shouldReplayVideo.android.ts | 2 +- src/components/VideoPlayer/shouldReplayVideo.ios.ts | 2 +- src/components/VideoPlayer/shouldReplayVideo.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/VideoPlayer/shouldReplayVideo.android.ts b/src/components/VideoPlayer/shouldReplayVideo.android.ts index c66a32f312e0..c1c3de034aac 100644 --- a/src/components/VideoPlayer/shouldReplayVideo.android.ts +++ b/src/components/VideoPlayer/shouldReplayVideo.android.ts @@ -1,4 +1,4 @@ -import {AVPlaybackStatusSuccess} from 'expo-av'; +import type {AVPlaybackStatusSuccess} from 'expo-av'; /** * Whether to replay the video when users press play button diff --git a/src/components/VideoPlayer/shouldReplayVideo.ios.ts b/src/components/VideoPlayer/shouldReplayVideo.ios.ts index f53f1e7eba4d..0a923d430699 100644 --- a/src/components/VideoPlayer/shouldReplayVideo.ios.ts +++ b/src/components/VideoPlayer/shouldReplayVideo.ios.ts @@ -1,4 +1,4 @@ -import {AVPlaybackStatusSuccess} from 'expo-av'; +import type {AVPlaybackStatusSuccess} from 'expo-av'; /** * Whether to replay the video when users press play button diff --git a/src/components/VideoPlayer/shouldReplayVideo.ts b/src/components/VideoPlayer/shouldReplayVideo.ts index 0a6cccac98ed..3a55562d4bd2 100644 --- a/src/components/VideoPlayer/shouldReplayVideo.ts +++ b/src/components/VideoPlayer/shouldReplayVideo.ts @@ -1,9 +1,9 @@ -import {AVPlaybackStatusSuccess} from 'expo-av'; +import type {AVPlaybackStatusSuccess} from 'expo-av'; /** * Whether to replay the video when users press play button */ -// eslint-disable-next-line no-unused-vars +// eslint-disable-next-line @typescript-eslint/no-unused-vars export default function shouldReplayVideo(e: AVPlaybackStatusSuccess, isPlaying: boolean, duration: number, position: number): boolean { return false; }