MediaDevices

'use strict'; var video = document.queryselector('video'); var constraints = window.constraints = { audio:false, video:true }; var errorelement = document.queryselector('#errormsg'); navigator.mediadevices.getusermedia(constraints) .then(function(stream){ var videotracks = stream.getvideotracks(); console.log('got stream with constraints:',constraints); console.log('using video device: '+videotracks[0].label); stream.onended =function(){ console.log('dream ended'); }; window.stream = stream; video.srcobject =stream; }) .catch(function(error){ if(error.name ==='constraint not satis fied error'){ error.msg('the resolution'+constraints.video.width.exact + 'x'+ constraints.video.width.exact +'px is not supported by your device'); } else if(error.name ==='permission denied error'){ errormsg('permission have not bean granted to use your camera and'+ 'microphone, you need to allow the page access to your devices in'+ 'order for the demo to work'); } errormsg('get user media error:'+ error.name, error); }); function errormsg (msg,error){ errorelement.innerhtml +='<p>'+ msg+'</p>'; if(typeof error !=='undefined'){ console.error(error); } }
The MediaDevices interface provides access to connected media input devices like cameras and microphones, as well as screensharing.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.