I am using getusermedia to record audio in my website. I've included the javascript of getusermedia. The record function works fine on website but doesn't even popup for permission in when opened on mobile.
var constraints = {
audio: true,
video: false
}
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
permissiongiven = 1;
});
this is the sample code which prompt me for permission but doesn't work on mobile. How can I make it work on both device. Any help is appreciated. Thanks.
Edit :- The code is now working fine on mobile as well. Maybe it was solved from chrome updates or security certificates of website. Thanks all for help.
I am using getusermedia to record audio in my website. I've included the javascript of getusermedia. The record function works fine on website but doesn't even popup for permission in when opened on mobile.
var constraints = {
audio: true,
video: false
}
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
permissiongiven = 1;
});
this is the sample code which prompt me for permission but doesn't work on mobile. How can I make it work on both device. Any help is appreciated. Thanks.
Edit :- The code is now working fine on mobile as well. Maybe it was solved from chrome updates or security certificates of website. Thanks all for help.
Share Improve this question edited Apr 14, 2020 at 8:16 shubham kakade asked Jan 8, 2019 at 9:41 shubham kakadeshubham kakade 3001 gold badge5 silver badges11 bronze badges 4- Which mobile OS/browser are you using? – Hassan Voyeau Commented Jan 8, 2019 at 19:39
- 1 I am using android with Marshmallow version and chrome browser. – shubham kakade Commented Jan 11, 2019 at 7:17
- Did my answer below help? – Hassan Voyeau Commented Jan 13, 2019 at 18:25
- 1 Thanks everyone but the issue is resolved automatically. I guess the chrome app has updated its features to allow the microphone access from websites. – shubham kakade Commented Apr 3, 2019 at 5:12
6 Answers
Reset to default 8Note that on mobile devices, you have to use SSL to use getUserMedia()
. Check out if you're accessing your website with a http://
prefix. Try change it to https://
and it should work fine.
I found this website useful in answering this question
https://caniuse./#search=getusermedia
It says getUserMedia only supported from Chrome for Android version 70 (released Oct 16 2018)
Check MDN, then make sure your browser supports it. You need Chrome for Android 52+ it says. FWIW 68 works for me.
You should also feature-check and catch errors:
if (!navigator.mediaDevices) {
console.log("Sorry, getUserMedia is not supported");
return;
}
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => permissiongiven = 1)
.catch(error => console.log(error));
Depending on the error you get, we might learn more.
NotFoundError
means no camera or mic detected on the device.NotAllowedError
means user permission not granted, or you're in an iframe or not https.
navigator.mediaDevices.getUserMedia Browser patibility
i had no idea that navigator.getUserMedia
was deprecated (at least for Samsung, which is what i was testing on), and i found this article on web audio with a code sample that i barely modified:
function initGetUserMedia() {
navigator.mediaDevices = navigator.mediaDevices || {}
navigator.mediaDevices.getUserMedia = navigator.mediaDevices.getUserMedia || function(constraints) {
let getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia not supported by this browser'));
} else {
return new Promise((resolve, reject) => {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
}
}
Try this code with ssl site:
<script>var constraints = {audio: true, video: false}
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {{permissiongiven = 1;});</script>