1
0
mirror of https://github.com/tooot-app/app synced 2024-12-22 07:34:06 +01:00

Merge pull request #492 from de1acr0ix/fullscreen-video-play-from-start

Always play video in fullscreen from beginning
This commit is contained in:
xmflsct 2022-12-04 14:49:23 +01:00 committed by GitHub
commit 35bf588b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,6 @@ const AttachmentVideo: React.FC<Props> = ({
const videoPlayer = useRef<Video>(null)
const [videoLoading, setVideoLoading] = useState(false)
const [videoLoaded, setVideoLoaded] = useState(false)
const [videoPosition, setVideoPosition] = useState<number>(0)
const [videoResizeMode, setVideoResizeMode] = useState<ResizeMode>(ResizeMode.COVER)
const playOnPress = useCallback(async () => {
setVideoLoading(true)
@ -34,19 +33,15 @@ const AttachmentVideo: React.FC<Props> = ({
await videoPlayer.current?.loadAsync({ uri: video.url })
}
Platform.OS === 'android' && setVideoResizeMode(ResizeMode.CONTAIN)
await videoPlayer.current?.setPositionAsync(videoPosition)
await videoPlayer.current?.presentFullscreenPlayer()
videoPlayer.current?.playAsync()
setVideoLoading(false)
videoPlayer.current?.setOnPlaybackStatusUpdate(props => {
if (props.isLoaded) {
setVideoLoaded(true)
if (props.positionMillis) {
setVideoPosition(props.positionMillis)
}
}
})
}, [videoLoaded, videoPosition])
}, [videoLoaded])
const appState = useRef(AppState.currentState)
useEffect(() => {
@ -107,7 +102,7 @@ const AttachmentVideo: React.FC<Props> = ({
if (event.fullscreenUpdate === VideoFullscreenUpdate.PLAYER_DID_DISMISS) {
Platform.OS === 'android' && setVideoResizeMode(ResizeMode.COVER)
if (!gifv) {
await videoPlayer.current?.pauseAsync()
await videoPlayer.current?.stopAsync()
}
}
}}