bugfix / Update video preview functionality (#3433)

* Add video preview functionality and update dependencies
* Refactor video preview component to use Buffer for base64 decoding and update muted prop syntax

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
Sanjai Kumar 2024-11-20 17:34:00 +05:30 committed by GitHub
parent 412a0ed078
commit 77d3fa7e1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 4 deletions

View File

@ -66,6 +66,7 @@
"react-i18next": "^15.0.1", "react-i18next": "^15.0.1",
"react-inspector": "^6.0.2", "react-inspector": "^6.0.2",
"react-pdf": "9.1.1", "react-pdf": "9.1.1",
"react-player": "^2.16.0",
"react-redux": "^7.2.6", "react-redux": "^7.2.6",
"react-tooltip": "^5.5.2", "react-tooltip": "^5.5.2",
"sass": "^1.46.0", "sass": "^1.46.0",

View File

@ -1,14 +1,41 @@
import React, { useState, useEffect } from 'react';
import CodeEditor from 'components/CodeEditor/index'; import CodeEditor from 'components/CodeEditor/index';
import { get } from 'lodash'; import { get } from 'lodash';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions'; import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
import { Document, Page } from 'react-pdf'; import { Document, Page } from 'react-pdf';
import { useState } from 'react';
import 'pdfjs-dist/build/pdf.worker'; import 'pdfjs-dist/build/pdf.worker';
import 'react-pdf/dist/esm/Page/AnnotationLayer.css'; import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
import 'react-pdf/dist/esm/Page/TextLayer.css'; import 'react-pdf/dist/esm/Page/TextLayer.css';
import { GlobalWorkerOptions } from 'pdfjs-dist/build/pdf'; import { GlobalWorkerOptions } from 'pdfjs-dist/build/pdf';
GlobalWorkerOptions.workerSrc = 'pdfjs-dist/legacy/build/pdf.worker.min.mjs'; GlobalWorkerOptions.workerSrc = 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
import ReactPlayer from 'react-player';
const VideoPreview = memo(({ contentType, dataBuffer }) => {
const [videoUrl, setVideoUrl] = useState(null);
useEffect(() => {
const videoType = contentType.split(';')[0];
const byteArray = Buffer.from(dataBuffer, 'base64');
const blob = new Blob([byteArray], { type: videoType });
const url = URL.createObjectURL(blob);
setVideoUrl(url);
return () => URL.revokeObjectURL(url);
}, [contentType, dataBuffer]);
if (!videoUrl) return <div>Loading video...</div>;
return (
<ReactPlayer
url={videoUrl}
controls
muted={true}
width="100%"
height="100%"
onError={(e) => console.error('Error loading video:', e)}
/>
);
});
const QueryResultPreview = ({ const QueryResultPreview = ({
previewTab, previewTab,
@ -73,9 +100,7 @@ const QueryResultPreview = ({
); );
} }
case 'preview-video': { case 'preview-video': {
return ( return <VideoPreview contentType={contentType} dataBuffer={dataBuffer} />;
<video controls src={`data:${contentType.replace(/\;(.*)/, '')};base64,${dataBuffer}`} className="mx-auto" />
);
} }
default: default:
case 'raw': { case 'raw': {