Skip to content
Merged
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
28 changes: 28 additions & 0 deletions src/components/VideoPlayerPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useThumbnailDimensions from '@hooks/useThumbnailDimensions';
import getPlatform from '@libs/getPlatform';
import Navigation from '@navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import VideoPlayerThumbnail from './VideoPlayerThumbnail';

Expand Down Expand Up @@ -65,6 +67,32 @@ function VideoPlayerPreview({videoUrl, thumbnailUrl, reportID, fileName, videoDi
const isOnSearch = useIsOnSearch();
const navigation = useNavigation();

useEffect(() => {
const platform = getPlatform();
// On web and desktop platforms, we can use the DOM video element to get accurate video dimensions
// by loading the video metadata. On mobile platforms, we rely on the provided videoDimensions
// since document.createElement is not available in React Native environments.
if (videoUrl && (platform === CONST.PLATFORM.WEB || platform === CONST.PLATFORM.DESKTOP)) {
Comment thread
amyevans marked this conversation as resolved.
const video = document.createElement('video');
video.onloadedmetadata = () => {
if (video.videoWidth === measuredDimensions.width && video.videoHeight === measuredDimensions.height) {
return;
}
setMeasuredDimensions({
width: video.videoWidth,
height: video.videoHeight,
});
};
video.src = videoUrl;
video.load();

return () => {
video.src = '';
};
}
setMeasuredDimensions(videoDimensions);
}, [videoUrl, measuredDimensions.width, measuredDimensions.height, videoDimensions]);

// We want to play the video only when the user is on the page where it was initially rendered
const doesUserRemainOnFirstRenderRoute = useCheckIfRouteHasRemainedUnchanged(videoUrl);

Expand Down
Loading