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)
| 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 | |
| 214 | async def list_devices(): |