这是Mac还是Canary中的BUG?
我需要通过Google Canary使用屏幕截图,以前在旧版本中都可以使用。
但是自从他们发布Canary M37或M39以来,它不再工作了。我的--enable-usermedia-screen-captureing命令对我执行它的方式无效吗?
$ 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>
最佳答案
在较新版本的Chrome中,不建议使用这种类型的屏幕截图,并且我相信已将其删除。
This started with Chrome M36+。
The new DesktopCapture API更好,并提供了更多的选择范围。
编辑:
只有通过扩展使用时,新的API才可用。 Chrome小组指出,出于安全原因,此设置已更改。将来,可能会将其移回以不需要构建扩展,但是从现在开始,它不能直接在页面中使用。
关于javascript - Google Canary-在Macbook Air OSX 10.9.4上报错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25763088/