Created
May 16, 2020 19:33
-
-
Save jimmywim/b480db79e448a5cbd2c8da0f53cf9f6f to your computer and use it in GitHub Desktop.
Test Video
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
<html> | |
<head> | |
<script> | |
function startVideo() { | |
const video = document.querySelector('video'); | |
const constraints = { | |
video: true | |
}; | |
navigator.mediaDevices.getUserMedia(constraints). | |
then((stream) => { video.srcObject = stream }); | |
} | |
function stopVideo() { | |
video = document.querySelector('video'); | |
console.log(video); | |
video.srcObject = null; | |
navigator.mediaDevices.getUserMedia({ video: true }).then( | |
function (stream) { | |
console.log(stream.getTracks().length); | |
stream.getTracks().forEach(function (track) { | |
console.log("Found a stream that needs to be stopped.") | |
track.stop(); | |
}); | |
console.log(stream.getTracks().length); | |
}).catch( | |
function (error) { | |
console.log('getUserMedia() error', error); | |
}); | |
} | |
</script> | |
<style> | |
video { | |
width: 300px; | |
height: 300px; | |
} | |
</style> | |
</head> | |
<body> | |
<input type="button" value="Start Video" onclick="javascript:startVideo()" /> | |
<input type="button" value="Stop Video" onclick="javascript:stopVideo()" /> | |
<video autoplay></video> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment