Created
June 5, 2014 08:11
-
-
Save er-rishi/5b1faaa03d16b9731c1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Get mediastream | |
*/ | |
var userStream; | |
navigator.getUserMedia = ( navigator.getUserMedia || | |
navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia || | |
navigator.msGetUserMedia); | |
if (navigator.getUserMedia) { | |
navigator.getUserMedia ( | |
// constraints | |
{ | |
video: true, | |
audio: true | |
}, | |
// successCallback | |
function(localMediaStream) { | |
// Assign mediastream to global variable | |
userStream = localMediaStream; | |
var video = document.querySelector('video'); | |
video.src = window.URL.createObjectURL(localMediaStream); | |
// Do something with the video here, e.g. video.play() | |
}, | |
// errorCallback | |
function(err) { | |
console.log("The following error occured: " + err); | |
} | |
); | |
} else { | |
console.log("getUserMedia not supported"); | |
} | |
/* | |
* To remove Audio Track | |
*/ | |
var audioTrack = userStream.getAudioTracks(); | |
if (audioTrack.length > 0) { | |
userStream.removeTrack(audioTrack[0]); | |
var video = document.querySelector('video'); | |
video.src = window.URL.createObjectURL(userStream); | |
} | |
/* | |
* To remove Video Track | |
*/ | |
var videoTrack = userStream.getVideoTracks(); | |
if (videoTrack.length > 0) { | |
userStream.removeTrack(videoTrack[0]); | |
var video = document.querySelector('video'); | |
video.src = window.URL.createObjectURL(userStream); | |
// Option-1 | |
$('video').css('display', 'none'); | |
// Option-2 | |
var audio = document.querySelector('audio'); | |
audio.src = window.URL.createObjectURL(userStream); | |
$('video').attr('src', ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment