Click here to Skip to main content
15,034,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to set the mime type for my a stream object returned from a recorded object
but the video element previews an incorrect mime-type error

Below Is The Full Code

JavaScript
import React, { Component } from 'react'

export default class Video extends Component {
    componentDidMount = () => {
        var MsStream;
        const hasStream = () => {
            navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia
            return navigator.getUserMedia
        }

        function getMedia() {
            const constraints = { video: true, audio: false }
            navigator.getUserMedia(constraints,
                (stream) => {
                    MsStream = stream
                    const video = document.querySelector(".show")
                    video.srcObject = stream
                    record()
                    video.onloadedmetadata = () => video.play()
                }, (error) => {
                    console.log("Nothing Is Coming Out")
                })

        }
        hasStream() && getMedia()

        function record() {

            const recorder = new MediaRecorder(MsStream)
            var chunks = []
            document.querySelector(".start").onclick = () => {
                console.log(recorder.state)
                recorder.start()
            }

            recorder.ondataavailable = (event) => {
                chunks.push(event.data)
            }

            document.querySelector(".stop").addEventListener("click", () => {
                console.log(recorder.state)
                recorder.stop()
                var blob = new Blob(chunks, { "type": 'video/mp4' })
                const video = document.querySelector("#saved")
                video.src = window.URL.createObjectURL(blob)
            })

        }
    }

}


What I have tried:

JavaScript
document.querySelector(".stop").addEventListener("click", () => {
                console.log(recorder.state)
                recorder.stop()
                var blob = new Blob(chunks, { "type": 'video/mp4' })
                const video = document.querySelector("#saved")
                video.src = window.URL.createObjectURL(blob)
            })
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900