UI_Dev
UI_Dev

Reputation: 200

DOMException: Requested device not found GetUserMedia

Trying to access IP Camera that is connected to a wifi.

I am connected to that wifi but I am getting error. If I try open using vlc I am able to connect but not getUserMedia has null.

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
})
export class HomeComponent {
  @ViewChild('video') video: any; 
  constructor() {
  }
  hasGetUserMedia() {
  return !!(navigator.mediaDevices &&
    navigator.mediaDevices.getUserMedia);
}


ngAfterViewInit() {
  if (this.hasGetUserMedia()) {
    // Good to go!
    console.log("Gooddd................");
  } else {
    alert('getUserMedia() is not supported by your browser');
  }
  let _video = this.video.nativeElement;
  if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
    navigator.mediaDevices.getUserMedia({ video: true, audio: true })
      .then(function (stream) {
        _video.src = window.URL.createObjectURL(stream);
        _video.play();
      }).catch(function (err) {
        console.log(err);
      });
    }
  }
}

<video #video width="640" height="480" autoplay></video>

Upvotes: 11

Views: 52644

Answers (8)

Yilmaz
Yilmaz

Reputation: 49681

I have mic and camera but I was getting the same error. I was pretty sure that was related to laptop setting, because I tried everything. turns out my laptop was blocking access to the media. I am using linux and laptop brand name is MSI, I started to look for any sign that related to the camera setting. On F6 button, my laptop has a webcam icon. So I clicked on

fn + F6

It works now. most likely sometimes I click on fn+* keys to see any difference and I blocked the camera access.

Upvotes: 0

davidtingsu
davidtingsu

Reputation: 1180

This issue can also occur on some mobile devices (Sony XA2 running Android) if you had previously already created a MediaStream.

The solution that I found was to make sure to stop all the tracks of previous streams that you created.

 this.stream.getTracks().forEach(t => {
    t.stop();
    // I don't think removeTrack is necessary, but just keeping it.
    this.stream.removeTrack(t);
 });

Without the previous code you can't seem to toggle camera on certain Android devices: (Demo), (Code) The error shown was DOMException: Requested device not found

By stopping previous tracks: you are able to start a new stream: (Demo) Code

Note: I also answered a related question here: https://stackoverflow.com/a/73550841/1123985

Upvotes: 0

Ajani Timothy
Ajani Timothy

Reputation: 224

Try attaching an earpiece or earplug with microphone to your PC. mine has no microphone that was why I got that error

Upvotes: 0

Joginder Tanikella
Joginder Tanikella

Reputation: 136

Use this line to initialize the webcam and microphone:

navigator.mediaDevices.getUserMedia({ audio: true, video: true });

Upvotes: 1

Srikanth Gowda
Srikanth Gowda

Reputation: 6551

In my case i have connected external camera through USB i was able to get the devices, i was getting kind of devices as audiooutput and videoinput, and there was no audioinput(microphone device) but while i was requesting for devices i passed constraints as..

function Webcam(){
  this.constraints = {
    video: true,
    audio: true
  }
  this.userMedia = null;
  this.mediaDevices = navigator.mediaDevices;
  this.initialize = function(){
    this.userMedia = this.mediaDevices.getUserMedia(this.constraints);
  }
}

let webcam = new Webcam();
    webcam.initialize();

So Promise not satisified and getting error as Requested device not found.

Upvotes: 0

Try without "audio: true". Its help for my. (Microphone are not work). And check webcam on other sites. Maybe need check permissions for this page.

Upvotes: 6

buster95
buster95

Reputation: 720

This happens when you dont have any device to capture video or capture audio

try checking if your webcam and your microphone are working fine

Upvotes: 15

try changing this line:

_video.src = window.URL.createObjectURL(stream);

with this one:

_video.srcObject = stream;

Upvotes: 1

Related Questions