Change create.objectURL to Htmlmediaelement.srcObject

Asked

Viewed 68 times

0

When adding the createObjectURL class, it is accusing the failed error in some browsers, after searching, I found that I can use Htmlmediaelement. But how can I include you in my project?

export class CameraController {

    constructor(videoEl){

        this._videoEl = videoEl;

        navigator.mediaDevices.getUserMedia({
            video:true
        }).then(stream=>{

        this._stream = stream;
        this._videoEl.src = URL.createObjectURL(stream);
        this.videoEl.play(); 

        }).catch(err=>{
            console.error(err);
        });
    }

    stop(){

        this._stream.getTracks().forEach(track=>{
            track.stop();
        });
    }

    takePicture(mimeType = 'image/png'){

        let canvas = document.createElement('canvas');

        canvas.setAttribute('height', this._videoEl.videoHeight);
        canvas.setAttribute('width', this._videoEl.videoWidth);

        let context = canvas.getContext('2d');

        context.drawImage(this._videoEl, 0, 0, canvas.width, canvas.height);

        return canvas.toDataURL(mimeType);

    }
}
  • What’s the mistake????

  • Typeerror: Failed to execute 'createObjectURL' on 'URL': No Function was found that Matched the Signature provided. at Cameracontroller.navigator.mediaDevices.getUserMedia.then.stream (Bundle.js:9763)

  • I checked that it is the createObjectURL that is already disabled in Chrome because in opera it still works but receives a warning message that is deprecated the code.

  • would not be window.URL.createObjectURL(stream);?

  • you can also try this._videoEl.srcObject = stream;

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.