React video recording not displaying in the video element

I'm currently developing a React application that facilitates webcam interviews with candidates. As part of this process, candidates have the option to "Start Again" or "Complete" their interviews.

One challenge I am facing is displaying the recorded data as an HTML video. The issue arises when the video does not appear after recording, particularly because the video data is in blob format.

In addition to this, a download button has been included for users. When users utilize this feature, they are able to successfully download and save the video locally.

Various solutions have been attempted to address the display problem. These solutions range from directly embedding the video using .mp4 or .webm extensions in the src attribute to experimenting with third-party React video player npm packages. Unfortunately, none of these methods have yielded successful results thus far.

... (proceeding with code snippet)

Answer №1

note: I don't use React so please try to fix any mistake(s) below:

To resolve the issue, you should update the video tag's source with your blob data.

Here is a suggestion to get started with the above concept:

(1). Utilize this setup for your <video> tag (example: ensure to assign a ref for this element):

<video
  ref={videoRef}
  type="video/mp4"
  src=""
  controls
  style={{ width: '100%', height: '100%', objectFit: 'cover' }}
  onError={(e) => { console.log('Error', e); }}
/>

(2) Next, utilize the \\Download Video function to enable playback of the blob data (assuming it contains valid information):

//# Download Video
const handleDownload = React.useCallback(() => {
 if (recordedChunks.length) 
 {
   const blob = new Blob(recordedChunks, { type: 'video/webm' });
   const url = URL.createObjectURL(blob);
   
   //# test playback ...
   videoRef.current.src = url;
   videoRef.current.load();
   videoRef.current.play();
   
   //# save as file
   const a = document.createElement('a');
   document.body.appendChild(a);
   a.style = 'display: none';
   a.href = url;
   a.download = 'react-webcam-stream-capture.webm';
   a.click();
   window.URL.revokeObjectURL(url);
   setRecordedChunks([]);
 }
}, [recordedChunks] );

PS: One thing to keep in mind is that on Apple devices, the video may be received as type video/mp4 instead of video/webm. It is noted that Safari browser on iOS generates an MP4 video. Consider whether your operating system and/or browser are impacting the result if the HTML tag is still not functioning properly.
For instance: Is the issue due to setting as video/webm in Safari on a Mac / iPad / iPhone?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm struggling with getting the state.map function in react.js to display the data correctly

Encountering an issue with my code. Trying to fetch data from the server-side (node.js) and saving it using setState(data), the console.log(this.state.data) displays all the data, but mapping it returns nothing. Interestingly, when creating an object in C ...

JavaScript, AJAX rapid iteration

I am working with some ajax code: $(document).ready( function() { $("#button1").click( function() { $.ajax({ type: "POST", url: "update.php", }); }); }); In my HTML code, I have 200 buttons. How can I ...

React Form with Conditional Input Options and Validation

Just diving into the world of React, I find myself connecting a React frontend to a Flask backend in a group project. Surprisingly, I've ended up handling about 90% of the workload. While I have utilized MUI for implementing fields, my focus is more o ...

The main-panel div's width increase is causing the pages to extend beyond the window's width limit

I recently downloaded a Reactbootstrap theme and managed to integrate it with NextJS successfully. However, I am facing an issue where my <div className="main-panel"> in the Layout.js is extending slightly beyond the window. It seems like t ...

ng-enter animation not working for ui-view nested within another ui-view after page reload

It seems like the issue lies with the ng-enter event not being properly triggered in the lowest level of the ui view hierarchy. I'm unsure how to resolve this problem effectively. In my extensive angularjs application, nested sub-views work flawlessl ...

Use PHP to highlight the row that has been selected in an HTML table

I am currently working on a project where I have styled multiple HTML tables on my website using alternating gray and white bands. Now, my goal is to highlight the selected row in a darker shade of gray. I have experimented with various solutions, and the ...

Is there a way to change the rotation direction of my circular progress bar in mui?

How can I switch the rotation direction of a mui progress bar from left to right? I attempted to change it by using: transform: rotate(180deg); However, this did not have any effect. ...

Checking for the accuracy of the provided full name

There is a specific task at hand: The field labeled “First Name Last Name” must only contain 2 words, with each word being between 3 and 30 characters in length. Additionally, there should be only one space between the first and last name. The issue t ...

Is there a way to link dynamic server fields with VueJS?

How can I bind data posted by the server with Vue.js in order to display the data instead of field names? <script> module.exports = { data: function () { return { filedNameFromServer: ['{{filed1}}' ...

I am encountering difficulties retrieving data from the context API in React.js

I am facing an issue where I cannot retrieve all the user data using the mail received during login with the context API in React. The response from the context API returns empty, but when testing it in Postman, I can see all the user data. I'm strugg ...

How can I utilize the pick parameter in nuxtjs3 useFetch for selecting arrays or performing a deep pick?

Currently working on my nuxtjs3 project, where I am extracting data from an API. Specifically using jsonPlaceholder for this task. Extracting data from a single object is not a problem: const { data: useFetchOnly } = await useFetch('https://jsonplace ...

Maintain stack navigation in React Native's createSwitchNavigator even when switching screens

According to the documentation: "SwitchNavigator is designed to display only one screen at a time. By default, it does not support back actions and resets routes to their default state when switching away. This behavior aligns with our desired functionalit ...

Best method to generate an element using any jQuery selector string

What I want to accomplish I am looking to create an element that matches any given selector string. Here's a quick example: var targetString = "a.exaggerated#selector[data-myattr='data-here']"; var targetEl = $(targetString); if(!targetE ...

Encountering a 404 error when attempting to fetch @reach/router via NPM

I'm currently diving into the world of gatsbyjs, and I encountered an issue while setting up a project. After navigating to the newly created directory, I proceeded to run npm install which resulted in a 404 error related to fetching the @reach/<a ...

The function has exceeded the time limit of 60000 milliseconds. Please make sure that the callback is completed

Exploring the capabilities of Cucumber with Protractor has been an intriguing journey for me. As I delved into creating a feature in Gherkin language, outlining the steps and scenarios necessary for my end-to-end tests, a new world of possibilities opened ...

Halt of dispatcher playback occurs after a duration of 10 minutes with discord.js

Currently, I've been working on a music bot using discord.js. To handle audio streaming, I'm utilizing @discordjs/opus and ytdl-core-discord. Everything runs smoothly when testing the bot locally on my machine - songs from YouTube are played with ...

Why is React JS unable to discover my exported modules?

Upon running my React app, the console displayed the following error message: Failed to compile. ./src/components/login/index.js Attempted import error: 'Login' is not exported from './login'. Here is an overview of the folder struct ...

Grabbing a section of a URL through a bookmarklet: A simple guide

Recently, I've been using this handy bookmarklet: javascript:currentUrl=document.location.href;document.location.assign(currentUrl+'embed'); This neat tool grabs the current URL, such as www.example.com/knZg_INW8fL/, and adds embed to it f ...

Concerns arise with jQuery grid compatibility in Firefox browsers

I have found an interesting tutorial on draggable image boxes grid at this link. Although everything is functioning properly, I am encountering an issue with the drag function specifically on the home page when using Firefox. As a beginner in jQuery, I am ...

Unable to retrieve the field value from the Json Object

I have a JSON object that I need to parse and display in a data table, but I'm having trouble reading the contents of the object. Here is my JavaScript function: finalGrid: function(data){ console.log("Final Grid"); var strJson = JSON.strin ...