Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement control playback speed #36898

Merged
merged 6 commits into from
Feb 26, 2024
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
8 changes: 4 additions & 4 deletions src/components/Attachments/AttachmentView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ function AttachmentView({
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const [loadComplete, setLoadComplete] = useState(false);
const isVideo = typeof source === 'string' && Str.isVideo(source);
const isVideo = (typeof source === 'string' && Str.isVideo(source)) || (file && Str.isVideo(file.name));

useEffect(() => {
if (!isFocused) {
if (!isFocused && !(file && isUsedInAttachmentModal)) {
return;
}
updateCurrentlyPlayingURL(isVideo ? source : null);
}, [isFocused, isVideo, source, updateCurrentlyPlayingURL]);
}, [isFocused, isVideo, source, updateCurrentlyPlayingURL, file, isUsedInAttachmentModal]);

const [imageError, setImageError] = useState(false);

Expand Down Expand Up @@ -201,7 +201,7 @@ function AttachmentView({
);
}

if (isVideo || (file && Str.isVideo(file.name))) {
if (isVideo) {
return (
<AttachmentViewVideo
source={source}
Expand Down
7 changes: 5 additions & 2 deletions src/components/VideoPlayer/BaseVideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {Video, VideoFullscreenUpdate} from 'expo-av';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Hoverable from '@components/Hoverable';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
Expand All @@ -12,6 +13,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import * as Browser from '@libs/Browser';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import CONST from '@src/CONST';
import {videoPlayerDefaultProps, videoPlayerPropTypes} from './propTypes';
import shouldReplayVideo from './shouldReplayVideo';
import VideoPlayerControls from './VideoPlayerControls';
Expand Down Expand Up @@ -59,6 +61,7 @@ function BaseVideoPlayer({
const videoResumeTryNumber = useRef(0);
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const isCurrentlyURLSet = currentlyPlayingURL === url;
const isUploading = _.some(CONST.ATTACHMENT_LOCAL_URL_PREFIX, (prefix) => url.startsWith(prefix));

const togglePlayCurrentVideo = useCallback(() => {
videoResumeTryNumber.current = 0;
Expand Down Expand Up @@ -144,8 +147,8 @@ function BaseVideoPlayer({
if (shouldUseSharedVideoElement || url !== currentlyPlayingURL) {
return;
}
shareVideoPlayerElements(videoPlayerRef.current, videoPlayerElementParentRef.current, videoPlayerElementRef.current);
}, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, updateSharedElements, url]);
shareVideoPlayerElements(videoPlayerRef.current, videoPlayerElementParentRef.current, videoPlayerElementRef.current, isUploading);
}, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, updateSharedElements, url, isUploading]);

// append shared video element to new parent (used for example in attachment modal)
useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/VideoPlayer/shouldReplayVideo.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ 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) {
// When we upload an attachment on Android, didJustFinish is false and the duration is 0
// so we should return false if the duration is 0 to prevent auto-playing video when the video is uploading
if (!isPlaying && !e.didJustFinish && duration === position && duration !== 0) {
return true;
}
return false;
Expand Down
7 changes: 5 additions & 2 deletions src/components/VideoPlayerContexts/PlaybackContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ function PlaybackContextProvider({children}) {
);

const shareVideoPlayerElements = useCallback(
(ref, parent, child) => {
(ref, parent, child, isUploading) => {
currentVideoPlayerRef.current = ref;
setOriginalParent(parent);
setSharedElement(child);
playVideo();
// Prevents autoplay when uploading the attachment
if (!isUploading) {
playVideo();
}
},
[playVideo],
);
Expand Down
Loading