简体   繁体   中英

Why is 'mediaDevices.getUserMedia' slow on ios safari compared to other browsers?

I am working on a web application which records voice inputs from users. For some reason it takes much time on ios safari to get the media stream for recording through mediaDevices.getUsearMedia. I created following test page to measure the time delay across different browsers. I would really appreciate if someone can give an insight into this.

IOS safari - 600 to 800ms

Chrome Desktop - 4 ms

Chrome Android - 40 to 60ms

<!DOCTYPE html>
<html>
<body>

 <h1 style="margin: 100px">get user media time test</h1>
 <div width="300px" height="300px" style="margin: 100px">
     <button id="btn" style="height:100px; width:250px; font-size:25px;">call getUserMedia</button>
 </div>

 <script>
    var btn = document.getElementById("btn");
    btn.onclick = myFunction;                

    function myFunction() {
    var time1 = new Date().getTime();
    navigator.mediaDevices.getUserMedia({ video:false ,audio: true})
        .then(function(stream) {
            var time2 = new Date().getTime();
            var diff = time2-time1;
            console.log("delay "+ diff + "ms") 
        })
        .catch(function(err) {
            console.log('Error gettingUserMedia: %s', err);
        });
    }   
 </script>

</body>
</html>

Each browser implements getUserMedia in a whole different way. While keeping in mind that getUserMedia is a very complex operation, it's understandable that there are minor time differences when comparing each browser's response time.

What getUserMedia actually does is:

Access permission settings ► Check permissions for specific site ► Prompt user's approval (if necessary) ► Access hardware ► Modelize the stream element ► callback.

Each of these steps was implemented by each browser's developers. Minor implementation changes can lead to minor response time gaps.

Also keep in mind that while Google Chrome is more forgiving, iOS keeps a strict policy around user privacy, which can lead to higher response time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM