Accessing microphone with the help of getUsermedia on iOS Safari










5















I'm attempting to access the microphone on iOS Safari with the help of the getUserMedia. Below you can find a snippet of my code.






if (navigator.mediaDevices === undefined) 
navigator.mediaDevices = ;


if (navigator.mediaDevices.getUserMedia === undefined)
navigator.mediaDevices.getUserMedia = function(constraints)


navigator.mediaDevices.getUserMedia(
audio: true
).then(function(stream)
successCallBack(.......);
).catch(function(error)
debug.log(error);
..........
);





Yet the promise always catches an error, to be more specific an OverConstraintError.



message: "Invalid constraint", constraint: ""


This behaviour is unique for iOS Safari, on all other browsers (Chrome, Firefox, Safari osX) it works without any problem. Actually my issue ressembles a lot like this one => How to resolve iOS 11 Safari getUserMedia "Invalid constraint" issue, yet I'm not trying to use the camera. The only thing that interests me is the microphone.



I'm testing with a real iPhone (a 5 and X, both updated to the latest version), so it is not linked to the iPhone Simulator.



The access to the microphone is granted and the popup requesting permissions is also showing, so it is not an permissions issue.










share|improve this question
























  • Are you using private browsing? Some features, like local storage, are restricted in private browsing. Other features are not available if using UIWebView instead of WKWebView.

    – Jesper
    Nov 5 '18 at 8:27











  • I should have mentioned it in my post but I am not testing with private browsing. Indeed I already noticed that some things are not available in private browsing.

    – Joey Reinders
    Nov 5 '18 at 8:36











  • Is it resolved yet ?

    – Towkir Ahmed
    Nov 9 '18 at 22:47











  • @TowkirAhmet, no it is not yet resolved.

    – Joey Reinders
    Nov 12 '18 at 12:17















5















I'm attempting to access the microphone on iOS Safari with the help of the getUserMedia. Below you can find a snippet of my code.






if (navigator.mediaDevices === undefined) 
navigator.mediaDevices = ;


if (navigator.mediaDevices.getUserMedia === undefined)
navigator.mediaDevices.getUserMedia = function(constraints)


navigator.mediaDevices.getUserMedia(
audio: true
).then(function(stream)
successCallBack(.......);
).catch(function(error)
debug.log(error);
..........
);





Yet the promise always catches an error, to be more specific an OverConstraintError.



message: "Invalid constraint", constraint: ""


This behaviour is unique for iOS Safari, on all other browsers (Chrome, Firefox, Safari osX) it works without any problem. Actually my issue ressembles a lot like this one => How to resolve iOS 11 Safari getUserMedia "Invalid constraint" issue, yet I'm not trying to use the camera. The only thing that interests me is the microphone.



I'm testing with a real iPhone (a 5 and X, both updated to the latest version), so it is not linked to the iPhone Simulator.



The access to the microphone is granted and the popup requesting permissions is also showing, so it is not an permissions issue.










share|improve this question
























  • Are you using private browsing? Some features, like local storage, are restricted in private browsing. Other features are not available if using UIWebView instead of WKWebView.

    – Jesper
    Nov 5 '18 at 8:27











  • I should have mentioned it in my post but I am not testing with private browsing. Indeed I already noticed that some things are not available in private browsing.

    – Joey Reinders
    Nov 5 '18 at 8:36











  • Is it resolved yet ?

    – Towkir Ahmed
    Nov 9 '18 at 22:47











  • @TowkirAhmet, no it is not yet resolved.

    – Joey Reinders
    Nov 12 '18 at 12:17













5












5








5


2






I'm attempting to access the microphone on iOS Safari with the help of the getUserMedia. Below you can find a snippet of my code.






if (navigator.mediaDevices === undefined) 
navigator.mediaDevices = ;


if (navigator.mediaDevices.getUserMedia === undefined)
navigator.mediaDevices.getUserMedia = function(constraints)


navigator.mediaDevices.getUserMedia(
audio: true
).then(function(stream)
successCallBack(.......);
).catch(function(error)
debug.log(error);
..........
);





Yet the promise always catches an error, to be more specific an OverConstraintError.



message: "Invalid constraint", constraint: ""


This behaviour is unique for iOS Safari, on all other browsers (Chrome, Firefox, Safari osX) it works without any problem. Actually my issue ressembles a lot like this one => How to resolve iOS 11 Safari getUserMedia "Invalid constraint" issue, yet I'm not trying to use the camera. The only thing that interests me is the microphone.



I'm testing with a real iPhone (a 5 and X, both updated to the latest version), so it is not linked to the iPhone Simulator.



The access to the microphone is granted and the popup requesting permissions is also showing, so it is not an permissions issue.










share|improve this question
















I'm attempting to access the microphone on iOS Safari with the help of the getUserMedia. Below you can find a snippet of my code.






if (navigator.mediaDevices === undefined) 
navigator.mediaDevices = ;


if (navigator.mediaDevices.getUserMedia === undefined)
navigator.mediaDevices.getUserMedia = function(constraints)


navigator.mediaDevices.getUserMedia(
audio: true
).then(function(stream)
successCallBack(.......);
).catch(function(error)
debug.log(error);
..........
);





Yet the promise always catches an error, to be more specific an OverConstraintError.



message: "Invalid constraint", constraint: ""


This behaviour is unique for iOS Safari, on all other browsers (Chrome, Firefox, Safari osX) it works without any problem. Actually my issue ressembles a lot like this one => How to resolve iOS 11 Safari getUserMedia "Invalid constraint" issue, yet I'm not trying to use the camera. The only thing that interests me is the microphone.



I'm testing with a real iPhone (a 5 and X, both updated to the latest version), so it is not linked to the iPhone Simulator.



The access to the microphone is granted and the popup requesting permissions is also showing, so it is not an permissions issue.






if (navigator.mediaDevices === undefined) 
navigator.mediaDevices = ;


if (navigator.mediaDevices.getUserMedia === undefined)
navigator.mediaDevices.getUserMedia = function(constraints)


navigator.mediaDevices.getUserMedia(
audio: true
).then(function(stream)
successCallBack(.......);
).catch(function(error)
debug.log(error);
..........
);





if (navigator.mediaDevices === undefined) 
navigator.mediaDevices = ;


if (navigator.mediaDevices.getUserMedia === undefined)
navigator.mediaDevices.getUserMedia = function(constraints)


navigator.mediaDevices.getUserMedia(
audio: true
).then(function(stream)
successCallBack(.......);
).catch(function(error)
debug.log(error);
..........
);






javascript ios safari






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 '18 at 5:11









Towkir Ahmed

9491720




9491720










asked Nov 5 '18 at 8:14









Joey ReindersJoey Reinders

6414




6414












  • Are you using private browsing? Some features, like local storage, are restricted in private browsing. Other features are not available if using UIWebView instead of WKWebView.

    – Jesper
    Nov 5 '18 at 8:27











  • I should have mentioned it in my post but I am not testing with private browsing. Indeed I already noticed that some things are not available in private browsing.

    – Joey Reinders
    Nov 5 '18 at 8:36











  • Is it resolved yet ?

    – Towkir Ahmed
    Nov 9 '18 at 22:47











  • @TowkirAhmet, no it is not yet resolved.

    – Joey Reinders
    Nov 12 '18 at 12:17

















  • Are you using private browsing? Some features, like local storage, are restricted in private browsing. Other features are not available if using UIWebView instead of WKWebView.

    – Jesper
    Nov 5 '18 at 8:27











  • I should have mentioned it in my post but I am not testing with private browsing. Indeed I already noticed that some things are not available in private browsing.

    – Joey Reinders
    Nov 5 '18 at 8:36











  • Is it resolved yet ?

    – Towkir Ahmed
    Nov 9 '18 at 22:47











  • @TowkirAhmet, no it is not yet resolved.

    – Joey Reinders
    Nov 12 '18 at 12:17
















Are you using private browsing? Some features, like local storage, are restricted in private browsing. Other features are not available if using UIWebView instead of WKWebView.

– Jesper
Nov 5 '18 at 8:27





Are you using private browsing? Some features, like local storage, are restricted in private browsing. Other features are not available if using UIWebView instead of WKWebView.

– Jesper
Nov 5 '18 at 8:27













I should have mentioned it in my post but I am not testing with private browsing. Indeed I already noticed that some things are not available in private browsing.

– Joey Reinders
Nov 5 '18 at 8:36





I should have mentioned it in my post but I am not testing with private browsing. Indeed I already noticed that some things are not available in private browsing.

– Joey Reinders
Nov 5 '18 at 8:36













Is it resolved yet ?

– Towkir Ahmed
Nov 9 '18 at 22:47





Is it resolved yet ?

– Towkir Ahmed
Nov 9 '18 at 22:47













@TowkirAhmet, no it is not yet resolved.

– Joey Reinders
Nov 12 '18 at 12:17





@TowkirAhmet, no it is not yet resolved.

– Joey Reinders
Nov 12 '18 at 12:17












2 Answers
2






active

oldest

votes


















0














This issue may be related to this bug report titled getUserMedia fails with an OverConstrainedError when no devices are found:



https://bugs.webkit.org/show_bug.cgi?id=177126



Here is your code running in Codepen. As you stated, audio is enabled and works. Note the enumerateDevices() call returns an empty array. As the bug states, this causes the error in your question:



.catch(function(error) 
navigator.mediaDevices.enumerateDevices().then(devices=>console.log(devices));
console.log('error: ',error);
);


https://codepen.io/anon/pen/rQWRyZ?editors=0011






share|improve this answer























  • indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

    – Joey Reinders
    Nov 15 '18 at 8:11


















0














web rtc or getusermedia has some issues and it is not working on all platforms as u expect - have same problems with camera detection like in samsung s5 same code is working fine but under newer device it was failing.



My advice is to use webrtc adapter js.
Try simply include this script:



<script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/6.4.0/adapter.js" type="text/javascript"></script>


before u use getusermedia api. I think that 99% of issues just disappear.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53150556%2faccessing-microphone-with-the-help-of-getusermedia-on-ios-safari%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This issue may be related to this bug report titled getUserMedia fails with an OverConstrainedError when no devices are found:



    https://bugs.webkit.org/show_bug.cgi?id=177126



    Here is your code running in Codepen. As you stated, audio is enabled and works. Note the enumerateDevices() call returns an empty array. As the bug states, this causes the error in your question:



    .catch(function(error) 
    navigator.mediaDevices.enumerateDevices().then(devices=>console.log(devices));
    console.log('error: ',error);
    );


    https://codepen.io/anon/pen/rQWRyZ?editors=0011






    share|improve this answer























    • indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

      – Joey Reinders
      Nov 15 '18 at 8:11















    0














    This issue may be related to this bug report titled getUserMedia fails with an OverConstrainedError when no devices are found:



    https://bugs.webkit.org/show_bug.cgi?id=177126



    Here is your code running in Codepen. As you stated, audio is enabled and works. Note the enumerateDevices() call returns an empty array. As the bug states, this causes the error in your question:



    .catch(function(error) 
    navigator.mediaDevices.enumerateDevices().then(devices=>console.log(devices));
    console.log('error: ',error);
    );


    https://codepen.io/anon/pen/rQWRyZ?editors=0011






    share|improve this answer























    • indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

      – Joey Reinders
      Nov 15 '18 at 8:11













    0












    0








    0







    This issue may be related to this bug report titled getUserMedia fails with an OverConstrainedError when no devices are found:



    https://bugs.webkit.org/show_bug.cgi?id=177126



    Here is your code running in Codepen. As you stated, audio is enabled and works. Note the enumerateDevices() call returns an empty array. As the bug states, this causes the error in your question:



    .catch(function(error) 
    navigator.mediaDevices.enumerateDevices().then(devices=>console.log(devices));
    console.log('error: ',error);
    );


    https://codepen.io/anon/pen/rQWRyZ?editors=0011






    share|improve this answer













    This issue may be related to this bug report titled getUserMedia fails with an OverConstrainedError when no devices are found:



    https://bugs.webkit.org/show_bug.cgi?id=177126



    Here is your code running in Codepen. As you stated, audio is enabled and works. Note the enumerateDevices() call returns an empty array. As the bug states, this causes the error in your question:



    .catch(function(error) 
    navigator.mediaDevices.enumerateDevices().then(devices=>console.log(devices));
    console.log('error: ',error);
    );


    https://codepen.io/anon/pen/rQWRyZ?editors=0011







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 1:26









    Randy CasburnRandy Casburn

    4,7611318




    4,7611318












    • indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

      – Joey Reinders
      Nov 15 '18 at 8:11

















    • indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

      – Joey Reinders
      Nov 15 '18 at 8:11
















    indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

    – Joey Reinders
    Nov 15 '18 at 8:11





    indeed the issues looks like the one stated in the webkit issue. The only problem I have is that the issue is not consistent, it comes and goes.

    – Joey Reinders
    Nov 15 '18 at 8:11













    0














    web rtc or getusermedia has some issues and it is not working on all platforms as u expect - have same problems with camera detection like in samsung s5 same code is working fine but under newer device it was failing.



    My advice is to use webrtc adapter js.
    Try simply include this script:



    <script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/6.4.0/adapter.js" type="text/javascript"></script>


    before u use getusermedia api. I think that 99% of issues just disappear.






    share|improve this answer



























      0














      web rtc or getusermedia has some issues and it is not working on all platforms as u expect - have same problems with camera detection like in samsung s5 same code is working fine but under newer device it was failing.



      My advice is to use webrtc adapter js.
      Try simply include this script:



      <script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/6.4.0/adapter.js" type="text/javascript"></script>


      before u use getusermedia api. I think that 99% of issues just disappear.






      share|improve this answer

























        0












        0








        0







        web rtc or getusermedia has some issues and it is not working on all platforms as u expect - have same problems with camera detection like in samsung s5 same code is working fine but under newer device it was failing.



        My advice is to use webrtc adapter js.
        Try simply include this script:



        <script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/6.4.0/adapter.js" type="text/javascript"></script>


        before u use getusermedia api. I think that 99% of issues just disappear.






        share|improve this answer













        web rtc or getusermedia has some issues and it is not working on all platforms as u expect - have same problems with camera detection like in samsung s5 same code is working fine but under newer device it was failing.



        My advice is to use webrtc adapter js.
        Try simply include this script:



        <script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/6.4.0/adapter.js" type="text/javascript"></script>


        before u use getusermedia api. I think that 99% of issues just disappear.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 22:02









        MackoMacko

        146210




        146210



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53150556%2faccessing-microphone-with-the-help-of-getusermedia-on-ios-safari%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto