Created
January 1, 2018 07:01
-
-
Save t2psyto/f9189acb15619a1e4d3b700a63d0ccf1 to your computer and use it in GitHub Desktop.
Brython webcam example
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
<!doctype html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>Camera with mediaDevice</title> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.4.0/brython.min.js"></script> | |
</head> | |
<body onload="brython()"> | |
<h1>Brython webcam example</h1> | |
<div id='main'><div> | |
<script type="text/python"> | |
import browser | |
from browser import html, document, window | |
aa = document['main'] | |
videotag = html.VIDEO(id='video', width='320', height='240') | |
aa.html = "" | |
aa <= videotag | |
from javascript import JSObject | |
createUrl = JSObject(window.URL.createObjectURL) | |
def OnSuccess(stream): | |
video = document['video'] | |
video.src = createUrl(stream) | |
video.play() | |
browser.window.navigator.mediaDevices.getUserMedia( | |
{"video": True, "audio": False} | |
).then(OnSuccess) | |
</script> | |
</body> | |
</html> |
Pierre, thanks for advice!
and sorry for did not noticing your comment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice !
You can simplify the Python code :
JSObject
is no longer needed (there is a deprecation message in the console), and you don't need to set an id to the video element.