Skip to content

Instantly share code, notes, and snippets.

@t2psyto
Created January 1, 2018 07:01
Show Gist options
  • Save t2psyto/f9189acb15619a1e4d3b700a63d0ccf1 to your computer and use it in GitHub Desktop.
Save t2psyto/f9189acb15619a1e4d3b700a63d0ccf1 to your computer and use it in GitHub Desktop.
Brython webcam example
<!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>
@t2psyto
Copy link
Author

t2psyto commented Mar 3, 2018

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