MediaDeviceApplyConstraints不工作

wrrgggsh  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(167)

我试图对视频曲目应用新的约束,但它不起作用:

<!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>

我希望在应用约束之前得到“1280960”,在应用约束之后得到“640480”。但我看到的是“1280960”。为什么?如何正确应用它?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题