sth*_*tfo 4 google-chrome webrtc getusermedia
chrome是否支持WebRTC的基于承诺的API?我无法让基于getUserMedia()承诺的API在Chrome中运行.
<!DOCTYPE html>
<html>
<head>
<title> Mitel WebRTC client </title>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src='dist/webrtc.min.js'></script>
<script type="text/javascript">
function startUp() {
var options = {
audio: true,
video: true
};
if (getUserMedia) {
getUserMedia(options)
.then(function (stream) {
console.log("Acquired audio and video!");
})
.catch(function (err) {
console.log(err.name + ": " + err.message);
});
} else {
alert("WebRTC not supported on this browser");
}
}
</script>
</head>
<body onload="startUp();">
<h1>WebRTC Promise API Client Application</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在控制台上,我看到以下错误
This appears to be Chrome
adapter-latest.js:32 chrome: {"audio":true,"video":true}
adapter-latest.js:410 Uncaught TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': The callback provided as parameter 2 is not a function.
Run Code Online (Sandbox Code Playgroud)
我想利用基于promise的API.我错过了什么吗?
jib*_*jib 12
它尚未在Chrome中实现,但如果您使用官方的adapter.js WebRTC polyfill,它可以在那里使用:https://jsfiddle.net/srn9db4h/
var constraints = { video: true, audio: true };
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => video.srcObject = stream)
.catch(e => console.error(e));
Run Code Online (Sandbox Code Playgroud)
Firefox和Edge本身支持FWIW.
更新: Chrome(50)似乎现在支持此功能.Chrome 52甚至支持srcObject.
| 归档时间: |
|
| 查看次数: |
11027 次 |
| 最近记录: |