MCPcopy Index your code
hub / github.com/pyscript/pyscript / get_stream

Method get_stream

core/src/stdlib/pyscript/media.py:181–211  ·  view source on GitHub ↗

Get a media stream from this specific device. ```python from pyscript.media import list_devices # List all devices. devices = await list_devices() # Find a specific camera. my_camera = None for device in devices: if dev

(self)

Source from the content-addressed store, hash-verified

179 return await cls.request_stream(audio=audio, video=video)
180
181 async def get_stream(self):
182 """
183 Get a media stream from this specific device.
184
185 ```python
186 from pyscript.media import list_devices
187
188
189 # List all devices.
190 devices = await list_devices()
191
192 # Find a specific camera.
193 my_camera = None
194 for device in devices:
195 if device.kind == "videoinput" and "USB" in device.label:
196 my_camera = device
197 break
198
199 # Get a stream from that specific camera.
200 if my_camera:
201 stream = await my_camera.get_stream()
202 ```
203
204 This will trigger a permission dialog if the user hasn't already
205 granted permission for this device type.
206 """
207 # Extract media type from device kind (e.g., "videoinput" -> "video").
208 media_type = self.kind.replace("input", "").replace("output", "")
209 # Request stream with exact device ID constraint.
210 options = {media_type: {"deviceId": {"exact": self.id}}}
211 return await self.request_stream(**options)
212
213
214async def list_devices():

Callers 2

connect_to_deviceFunction · 0.80
test_device_get_streamFunction · 0.80

Calls 1

request_streamMethod · 0.95

Tested by 1

test_device_get_streamFunction · 0.64