- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在以下初始化 WebRTC 的方法中收到了 Safari Tech Preview 11 中未处理的 Promise Rejection。具体来说,当我将 MediaStream
分配给视频元素时会发生这种情况:video.srcObject = event.stream;
- 堆栈跟踪显示这一行是抛出异常。我无法使用 try/catch.
异常仅发生在 Safari 11 中(不会发生在 Chrome 中)。
方法如下:
initWebRTC(p){
var self = this;
return new Promise((resolve, reject) => {
self.state.connection = new RTCMultiConnection();
self.state.connection.socketMessageEvent = 'webrtc-firebase';
self.state.connection.setCustomSocketHandler(FirebaseConnection);
self.state.connection.firebase = 'webrtc-firebase';
self.state.connection.enableFileSharing = true;
self.state.connection.session = {
audio: true,
video: true,
data: true
};
self.state.connection.sdpConstraints.mandatory = {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
};
self.state.connection.onstream = function(event) {
console.log('event.mediaElement',event.mediaElement);
console.log('event.stream',event.stream);
var videoContainer = document.getElementById('videoContainer');
var video = event.mediaElement;
if (!window.safari){
var source = document.createElement("source");
source.srcObject = event.stream;
video.appendChild(source);
} else { // Safari
try{
video.srcObject = event.stream; // this is the line that throws the exception
}catch(e){ //unable to catch the exception
console.log('exception',e);
}
}
videoContainer.appendChild(video);
var playPromise = video.play();
if (playPromise !== undefined) { // not a Promise in some browsers
playPromise.catch(function(error) {
});
}
setTimeout(function() {
var playPromise = video.play();
if (playPromise !== undefined) {
playPromise.catch(function(error) {
});
}
}, 5000);
};
resolve();
});
}
不确定这是否有帮助,但这是痕迹:
[Error] Unhandled Promise Rejection: [object DOMError]
(anonymous function)
rejectPromise
onstream (index.js:5787) // this is the video.srcObject = event.stream; line
(anonymous function) (RTCMultiConnection.js:4092)
getRMCMediaElement (RTCMultiConnection.js:1113)
onGettingLocalMedia (RTCMultiConnection.js:4064)
onGettingLocalMedia (RTCMultiConnection.js:4984)
streaming (RTCMultiConnection.js:3289)
(anonymous function) (RTCMultiConnection.js:3358)
promiseReactionJob
如有任何帮助,我们将不胜感激。谢谢!
最佳答案
Safari 11 默认阻止自动播放任何有声视频 (source)。
我相信 video
元素带有自动播放属性。当您为它设置 srcObject
时,它会尝试播放视频——然后被 Safari 阻止。这就是您看到错误的原因。
您可以尝试从视频元素中删除 autoplay
,然后您可以在 playPromise.catch
中捕获它。
关于javascript - MediaStream 未处理的 promise 拒绝 : [object DOMError] (in Safari 11),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45311263/
介绍 DOMError是由 DOM 定义的接口(interface)。 我想检查浏览器是否支持它。一个简单的检查是 window.DOMError !== undefined 更好的检查是使用抛出 D
今天我遇到了一个错误类型:抛出 DOMerror 异常。将浏览器留在空白页面。 经过一些研究后,我在 w3c 中发现它应该专门用于 indexeddb 异常。我实际上删除了cookie,清除了本地存储
当更改音频源然后立即调用播放时,我收到一个 DOMError 说操作已中止。所以我的播放 promise 被拒绝但音频播放正常。 这似乎是一个新问题(可能是从 12 月开始?),只附加在我的 safa
我正在尝试在 chrome 31 中使用 HTML5 文件系统 API。不幸的是,在用户授予对文件系统配额的访问权限后,我遇到了错误。 这是错误: Error DOMError {message: "
我在以下初始化 WebRTC 的方法中收到了 Safari Tech Preview 11 中未处理的 Promise Rejection。具体来说,当我将 MediaStream 分配给视频元素时会
我有一组 MP4 视频,当容器悬停时会播放。请查看本页底部的 3 张图片以获取演示: https://ts133842-container.zoeysite.com/ 这在 Chrome 中效果很好,
我是一名优秀的程序员,十分优秀!