0

我正在尝试对视频轨道应用新的约束,但它不起作用:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body onload="onLoad();">
    <p id="res1"></p>
    <p id="res2"></p>
<script>
    async function onLoad() {
        var opts1 = {audio: true, video: {advanced: [{ width: 1280, height: 960 },]}};
        var stream = await navigator.mediaDevices.getUserMedia(opts1);
        var cstr1 = stream.getVideoTracks()[0].getSettings();
        document.getElementById("res1").innerHTML = cstr1.width + ", " + cstr1.height;

        var opts2 = {audio: true, video: {advanced: [{ width: 640, height: 480 },]}};
        await stream.getVideoTracks()[0].applyConstraints(opts2);
        cstr2 = stream.getVideoTracks()[0].getSettings();
        document.getElementById("res2").innerHTML = cstr2.width + ", " + cstr2.height;
    }
    </script>
</body>
</html>

我希望在应用约束之前得到答案“1280, 960”,之后得到“640, 480”。但我看到的是“1280, 960”。为什么?我怎样才能正确应用它?

4

0 回答 0