当前位置:首页 > 操作系统 > MacOs

javascript-Google Canary-Macbook Air OSX 10.9.4上出现错误

这是Mac还是Canary中的BUG?

我需要通过Google Canary使用屏幕截图,以前在以前的旧版本中都可以使用.

但是自从他们发布Canary M37或M39以来,它不再工作了.我的–enable-usermedia-screen-captureing命令对我执行它的方式无效吗?

<code>$alias canary="open /Applications/Google Chrome Canary.app/ --args --enable-usermedia-screen-capturing"
$canary
</code>

现在,当我尝试开始屏幕捕获(在旧版本中运行)时,出现错误提示:

<code>getUserMedia error:  NavigatorUserMediaError {constraintName: "", message: "", name: "InvalidStateError"}
</code>

码:

<code>function start() {
  console.log("Requesting local stream");
  btn1.disabled = true;
  var video_constraints = { 
    audio: false,
    video: {
      mandatory: {
        chromeMediaSource: 'screen',
        maxWidth: 1024,
        maxHeight: 768,
        minWidth:800,
        minHeight:400,
        minFrameRate: 1,
        maxFrameRate: 2,
        //minAspectRatio: 1.333, maxAspectRatio: 1.334,
      }
    }
  };

  navigator.webkitGetUserMedia(video_constraints, function(stream){
    console.log("Received local stream");
    vid1.src = webkitURL.createObjectURL(stream);
    localstream = stream;


  }, function(e){

    console.log("getUserMedia error: ", e);
  });
}  
</code>

编辑:

<code><html>
<head>
<style>
  body {
    background: white;
    display: -webkit-flex;
    -webkit-justify-content: center;
    -webkit-align-items: center;
    -webkit-flex-direction: column;
  }
  video {
    width: 640px;
    height: 480px;
    border: 1px solid #e2e2e2;
    box-shadow: 0 1px 1px rgba(0,0,0,0.2);
  }
</style>
</head>
<body>
  <video id="video" autoplay></video>
  <p><button id="start">Start</button><button id="cancel">Cancel</button></p>
  <script>
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function gotStream(stream) {
  console.log("Received local stream");
  var video = document.querySelector("video");
  video.src = URL.createObjectURL(stream);
  localstream = stream;
  stream.onended = function() { console.log("Ended"); };
}

function getUserMediaError() {
  console.log("getUserMedia() failed.");
}

function onAccessApproved(id) {
  if (!id) {
    console.log("Access rejected.");
    return;
  }
  navigator.webkitGetUserMedia({
      audio:false,
      video: { mandatory: { chromeMediaSource: "desktop",
                            chromeMediaSourceId: id } }
  }, gotStream, getUserMediaError);
}

var pending_request_id = null;

document.querySelector('#start').addEventListener('click', function(e) {
  pending_request_id = chrome.desktopCapture.chooseDesktopMedia(
      ["screen", "window"], onAccessApproved);
});

document.querySelector('#cancel').addEventListener('click', function(e) {
  if (pending_request_id != null) {
    chrome.desktopCapture.cancelChooseDesktopMedia(pending_request_id);
  }
});

  </script>
</body>
</html>
</code>

解决方法:

在较新版本的Chrome中,不建议使用这种类型的屏幕截图,并且我相信已将其删除.

This started with Chrome M36+.

The new DesktopCapture API更好,并提供了更多选择.

编辑:

只有通过扩展使用新API才可用. Chrome小组指出,出于安全原因,此更改已更改.将来,可能会将其移回而不要求构建扩展,但截至目前,它不能直接在页面中使用.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐