//Wrap the getUserMedia function from the different browsers
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
//Our success callback where we get the media stream object and assign it to a video tag on the page
function onSuccess(mediaObj){
window.stream = mediaObj;
var video = document.querySelector("video");
video.src = window.URL.createObjectURL(mediaObj);
video.play();
}
//Our error callback where we will handle any issues
function onError(errorObj){
console.log("There was an error: " + errorObj);
}
//We can select to request audio and video or just one of them
var mediaConstraints = { video: true, audio: true };
//Call our method to request the media object - this will trigger the browser to prompt a request.
navigator.getUserMedia(mediaConstraints, onSuccess, onError);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.