Reputation: 197
Here is the HTML code
<video ref={videos} autoPlay ></video>
<Button onClick={() =>
navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((mediaStream) => {
videos.srcObject = mediaStream;
videos.onloadedmetadata = function(e) {
videos.play();
};
}
)}>Record</Button>
JS
const videos = createRef(null);
Error
Unhandled Rejection (TypeError): Cannot add property srcObject, object is not extensible
353 | <Button onClick={() =>
354 | navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((mediaStream) => {
355 |
> 356 | videos.srcObject= mediaStream;
357 | videos.onloadedmetadata = function(e) {
358 | videos.play();
359 | };
Upvotes: 0
Views: 4554
Reputation: 2289
After you create a ref to the video element, you must use the video.current
property to access the DOM element. Your code should look like this:
<video ref={videos} autoPlay ></video>
<Button onClick={() =>
navigator.mediaDevices.getUserMedia({audio: true, video: true})
.then((mediaStream) => {
videos.current.srcObject = mediaStream;
videos.current.onloadedmetadata = function(e) {
videos.current.play();
};
}
)}>Record</Button>
This should fix the problem.
Upvotes: 3