MCPcopy Index your code
hub / github.com/rawpython/remi / video_start

Method video_start

examples/examples_from_contributors/camera.py:20–44  ·  view source on GitHub ↗
(self, widget, callback_function)

Source from the content-addressed store, hash-verified

18 self.video.attributes['height'] = height
19
20 def video_start(self, widget, callback_function):
21 self.execute_javascript("""
22 var params={};
23 var frame = 0;
24 document.video_stop = false;
25 const video = document.querySelector('video');
26 video.setAttribute("playsinline", true);
27 const canvas = document.createElement('canvas');
28 navigator.mediaDevices.getUserMedia({video: { facingMode: { ideal: "environment" } }, audio: false}).
29 then((stream) => {video.srcObject = stream});
30 const render = () => {
31 if (document.video_stop) { return; }
32 if (frame==30) {
33 canvas.width = video.videoWidth;
34 canvas.height = video.videoHeight;
35 canvas.getContext('2d').drawImage(video, 0, 0);
36 params['image']=canvas.toDataURL()
37 remi.sendCallbackParam('%(id)s','%(callback_function)s',params)
38 frame = 0;
39 }
40 frame+=1;
41 requestAnimationFrame(render);
42 }
43 requestAnimationFrame(render);
44 """%{'id':str(id(self)), 'callback_function': str(callback_function)})
45
46 def video_stop(self, widget):
47 self.execute_javascript("""

Callers

nothing calls this directly

Calls 1

execute_javascriptMethod · 0.80

Tested by

no test coverage detected