1
0
mirror of https://github.com/tooot-app/app synced 2024-12-22 15:49:42 +01:00

Always play video in fullscreen from beginning

This commit is contained in:
Hanjiang Yu 2022-11-28 20:36:39 +08:00
parent bd750da9d5
commit 0a5fea1194

View File

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