Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  153] [ 5]  / answers: 1 / hits: 35328  / 6 Years ago, fri, june 29, 2018, 12:00:00

I get the warning that a function will be deprecated in Chrome future release.



It's this script:



navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({
video: true
}, (stream) => {
this.src = window.URL.createObjectURL(stream);
this.stream = stream;
}, (error) => {
console.log(error);
});
}


That records webcam so I can save it, but the following warning is shown in the console:




[Deprecation] URL.createObjectURL with media streams is deprecated
and will be removed in M68, around July 2018. Please use
HTMLMediaElement.srcObject instead.




But when I change:



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


To



this.src = window.HTMLMediaElement.srcObject(stream);


It doesn't work anymore like it did before..


More From » html

 Answers
18

Your misunderstanding what HTMLMediaElement is.


It is the JavaScript Class/Prototype that represents a HTML <audio> or <video> tag whether it's in the HTML or not.


For a more class like explanation
<audio> on the page is an object of type HTMLAudioElement and that extends HTMLMediaElement and that in turn extends HTMLElement.


If you get the media element with querySelector() or getElementById() or create a media element in JavaScript with createElement("audio") or createElement("video")
you'll get an instance of HTMLMediaElement.


In your case this is an object of HTMLMediaElement class.


With JavaScript, as a rule of thumb if the object type name starts with HTML it is referring to an HTML Element / Tag.


All you need to do is change


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

to


if ('srcObject' in this) {
this.srcObject = stream;
} else {
this.src = window.URL.createObjectURL(stream);
}

This is taken from Mozilla Documentation


[#54091] Monday, June 25, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katelinb

Total Points: 535
Total Questions: 104
Total Answers: 109

Location: Burkina Faso
Member since Sun, Jun 13, 2021
3 Years ago
;