gpt4 book ai didi

javascript - 如果我将音频设置为 true,适用于 Iphone 和 Ipad 的 Safari 自录视频会卡住

转载 作者:行者123 更新时间:2023-11-29 05:50:32 24 4
gpt4 key购买 nike

我已经使用 webrtc api 和 jQuery JavaScript 完成了应用程序视频聊天,但我在 iPhone 和 iPad 上的 Safari 中遇到问题,当我接收远程视频时,自身视频会卡住,只有当我将音频设置为 true 时才会发生这种情况在我的设置中,

 var constraint = {
video: {
minWidth: 270,
minHeight: 270,
minFrameRate: 25,
maxWidth: 270,
maxHeight: 270,
maxFrameRate: 25,
facingMode: 'user'
},
audio: false
}

有人可以帮我吗

最佳答案

我能够成功地解决这个问题,我将音频流和视频流分开,克隆我的全局流并以不同的方式处理两者,这是帮助我做到这一点的代码,我希望这对某人有帮助。

function makeAudioOnlyStreamFromExistingStream(stream) {
var audioStream = stream.clone();
var videoTracks = audioStream.getVideoTracks();
for (var i = 0, len = videoTracks.length; i < len; i++) {
audioStream.removeTrack(videoTracks[i]);
}
console.log('created audio only stream, original stream tracks: ', stream.getTracks());
console.log('created audio only stream, new stream tracks: ', audioStream.getTracks());
return audioStream;
}

function makeVideoOnlyStreamFromExistingStream(stream) {
var videoStream = stream.clone();
var audioTracks = videoStream.getAudioTracks();
for (var i = 0, len = audioTracks.length; i < len; i++) {
videoStream.removeTrack(audioTracks[i]);
}
console.log('created video only stream, original stream tracks: ', stream.getTracks());
console.log('created video only stream, new stream tracks: ', videoStream.getTracks());
return videoStream;
}
function handleSuccess(stream) {
var audioOnlyStream = makeAudioOnlyStreamFromExistingStream(stream);
var videoOnlyStream = makeVideoOnlyStreamFromExistingStream(stream);
// Do stuff with all the streams...
}
function handleError(error) {
console.error('getUserMedia() error: ', error);
}
var constraints = {
audio: true,
video: true,
};
navigator.mediaDevices.getUserMedia(constraints).
then(handleSuccess).catch(handleError);

完整的例子在这里

https://webrtchacks.com/guide-to-safari-webrtc/

关于javascript - 如果我将音频设置为 true,适用于 Iphone 和 Ipad 的 Safari 自录视频会卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55713551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com