Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allow camera access - show camera view -- don’t start recording video

Status
Not open for further replies.

chrisjchrisj

Technical User
Sep 13, 2006
5
US
This code below works successfully to capture/record/play video - after camera access permission is granted - when the start button is selected. I'm trying to add the functionality where (after camera access is allowed) the camera view appears, without recording starting automatically (And have the camera view displayed while recording).

Currently, the screen is black after camera access and while capture/recording. I was told that I need to "capture the stream from the video element and put it through the MediaRecorder object". I don't know how to do that. Any help is appreciated

Code:
 var video = document.querySelector("video");
let params = { audio: true, video: { facingMode: { exact: "environment" } } };

let blobs = [];
let stream, mediaRecorder, blob;

async function startRecording() {
stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: true,
});

mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = (event) => {
// Let's append blobs for now, we could also upload them to the network.
if (event.data) {
blobs.push(event.data);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top