0

I am using getUserMedia to displaying the live stream from the webcam.

My app.component.html is

// to show webcam video
<video id="vid1" autoplay></video>

// to show recieved stream from other user.
<video id="vid2" autoplay></video>

and app.component.ts

navigatorr.getUserMedia(constraints, function (stream) {
    const video = document.querySelector('#vid1');

    // inserting our stream to the video tag
    video.src = window.URL.createObjectURL(stream);

 }

It is giving an error that

Property 'src' does not exist on type 'Element'.

But If I am using

const video = document.querySelector('video');

It is working, But then How will I show the video of the received stream.

How to solve this problem, Please someone help me.

Rupesh
  • 850
  • 2
  • 13
  • 30

3 Answers3

2

You need to cast Element to HTMLVideoElement: Try this:

navigatorr.getUserMedia(constraints, function (stream) {
    const video = <HTMLVideoElement>(document.querySelector('#vid1'));

    // inserting our stream to the video tag
    video.src = window.URL.createObjectURL(stream);

 }
Ritesh Waghela
  • 3,474
  • 2
  • 19
  • 25
0

Try this

document.getElementById("vid1").src= window.URL.createObjectURL(stream);
jeff porter
  • 6,560
  • 13
  • 65
  • 123
Fahad Subzwari
  • 2,109
  • 3
  • 24
  • 52
0

In my case the following variant works:

navigator.getUserMedia(constraints, function (stream) {
    const video: HTMLVideoElement = document.querySelector('#vid1');

    // inserting our stream to the video tag
    video.src = window.URL.createObjectURL(stream);

 }

P.S. navigatorr !== navigator

Roman
  • 19,236
  • 15
  • 93
  • 97