【问题标题】:Google Canary - on Macbook Air OSX 10.9.4 is giving errorGoogle Canary - 在 Macbook Air OSX 10.9.4 上出现错误
【发布时间】:2014-09-10 10:29:08
【问题描述】:

这是 Mac 还是 Canary 中的 BUG?

我需要通过 Google Canary 使用屏幕捕获,这在过去的旧版本中是有效的。

但是由于他们发布了 Canary M37 或 M39,它不再工作了。我的 --enable-usermedia-screen-capturing 命令在我执行的方式上是否无效?

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

现在,当我尝试开始屏幕捕获(在旧版本中工作)时,它给了我错误失败:

getUserMedia error:  NavigatorUserMediaError {constraintName: "", message: "", name: "InvalidStateError"}

代码:

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);
  });
}  

编辑:

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

【问题讨论】:

  • 也试过 --usermedia-screen-capturing 但仍然getUserMedia error: NavigatorUserMediaErrorconstraintName: ""message: ""name: "InvalidStateError"__proto__: NavigatorUserMediaError

标签: javascript macos google-chrome webrtc


【解决方案1】:

在较新版本的 Chrome 中,这种类型的屏幕截图已被弃用,我相信已被删除。

This started with Chrome M36+.

The new DesktopCapture API 更好,提供更多选择。

编辑:

新 API 仅在通过扩展程序使用时可用。 Chrome 团队表示出于安全原因已对此进行了更改。可能在将来,它将被移回不需要构建扩展,但截至目前,它不能直接在页面中使用。

【讨论】:

  • 在 M39 中尝试您的建议时出现错误无法读取未定义的属性 'chooseDesktopMedia:pending_request_id = chrome.desktopCapture.chooseDesktopMedia(["screen", "window"], onAccessApproved);
  • 那么这很可能是一个错误,如果现在这两者都不能在 OSX 的 Chrome Canary 中工作...enable-usermedia-screen-capture 标志是否仍然存在于 Chrome 中?
  • 好吧,废话,看起来必须完成through an extension only。我认为尖端技术存在问题。
  • 如果没问题,请看我的回答。
  • 是的,必须在扩展程序中完成,我很高兴 Chrome 提供了一个易于使用的示例。
【解决方案2】:

第 1 步 - 下载现成的蛋糕,开始使用

https://developer.chrome.com/extensions/examples/api/desktopCapture.zip

第 2 步 - RTFM

Load the extension
Extensions that you download from the Chrome Web Store are packaged up as .crx files, which is great for distribution, but not so great for development. Recognizing this, Chrome gives you a quick way of loading up your working directory for testing. Let's do that now.

Visit chrome://extensions in your browser (or open up the Chrome menu by clicking the icon to the far right of the Omnibox:  The menu's icon is three horizontal bars.. and select Extensions under the Tools menu to get to the same place).

Ensure that the Developer mode checkbox in the top right-hand corner is checked.

Click Load unpacked extension… to pop up a file-selection dialog.

Navigate to the directory in which your extension files live, and select it.

Alternatively, you can drag and drop the directory where your extension files live onto chrome://extensions in your browser to load it.

If the extension is valid, it'll be loaded up and active right away! If it's invalid, an error message will be displayed at the top of the page. Correct the error, and try again.

第 3 步 - 启动应用程序

编辑:参考:

https://developer.chrome.com/extensions/manifest#web_accessible_resources

https://stackoverflow.com/a/17098011

https://stackoverflow.com/a/17120647

【讨论】:

    【解决方案3】:

    Firefox 现在也有屏幕/窗口/等捕获。目前,出于与 Chrome 类似的原因,我们已将对该功能的访问置于白名单之后(尽管扩展程序也可以扩展白名单;我们尚未对此进行原型设计)。

    参见http://mozilla.github.io/webrtc-landing/gum_test.html(在 Firefox 33 或更高版本中 - 目前是 Beta 版;没有尝试进行 polyfill,因为它是一个内部测试页面)。

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      相关资源
      最近更新 更多