gpt4 book ai didi

javascript - WebRTC远程视频显示为黑色

转载 作者:IT王子 更新时间:2023-10-29 03:12:51 27 4
gpt4 key购买 nike

在开发 WebRTC 视频聊天应用程序时,我遇到了接收远程视频流的情况。收到视频流 blob,但视频只是黑色。

我已经仔细阅读了这些答案并尝试了几乎所有可能的方法来让它工作 https://stackoverflow.com/a/17424224/923109 Remote VideoStream not working with WebRTC

......
Globalvars.socket.on('call', function (signal) {
if(!Globalvars.pc){
Methods.startCall(false, signal);
}

if(signal.sdp){
temp = new RTCSessionDescription({"sdp" : decodeURIComponent(signal.sdp), "type" : signal.type});
Globalvars.pc.setRemoteDescription(temp);
for(i = 0; i < Globalvars.iceCandidateArray.length; i++){
Globalvars.pc.addIceCandidate(new RTCIceCandidate({
sdpMLineIndex: decodeURIComponent(signal.sdpMLineIndex),
candidate: decodeURIComponent(signal.candidate)
}));
}

Globalvars.iceCandidateArray = [];
}
else{
if(Globalvars.pc.remoteDescription){
Globalvars.pc.addIceCandidate(new RTCIceCandidate({
sdpMLineIndex: decodeURIComponent(signal.sdpMLineIndex),
candidate: decodeURIComponent(signal.candidate)
}));
console.log("remot");
}
else{
Globalvars.iceCandidateArray.push(new RTCIceCandidate({
sdpMLineIndex: decodeURIComponent(signal.sdpMLineIndex),
candidate: decodeURIComponent(signal.candidate)
}));
console.log("ice candidate to temp array");
}
}
});


$("#roster-wrap").on("click", ".roster-list-item", function(e){
//Globalvars.socket.emit('call', {"receiver_id" : $(this).attr("data-id"), "caller_id" : Globalvars.me.id});
params = {"receiver_id" : $(this).attr("data-id"), "caller_id" : Globalvars.me.id};
Methods.startCall(true, params);
e.preventDefault();
});
.....


.....
// run start(true) to initiate a call
"startCall" : function (isCaller, params) {
var configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
Globalvars.pc = new RTCPeerConnection(configuration);

// send any ice candidates to the other peer
Globalvars.pc.onicecandidate = function (evt) {
//alert("ice candidate");
if (!Globalvars.pc || !evt || !evt.candidate) return;
var candidate = evt.candidate;
Globalvars.socket.emit("call",{ "candidate": encodeURIComponent(candidate.candidate), "sdpMLineIndex" : encodeURIComponent(candidate.sdpMLineIndex), "receiver_id" : params.receiver_id, "caller_id" : params.caller_id});
};

// once remote stream arrives, show it in the remote video element
Globalvars.pc.onaddstream = function (evt) {
console.log("add stream");
if (!event) return;
$("#remote-video").attr("src",URL.createObjectURL(evt.stream));
Methods.waitUntilRemoteStreamStartsFlowing();
};

// get the local stream, show it in the local video element and send it
navigator.getUserMedia({ "audio": false, "video": true }, function (stream) {
$("#my-video").attr("src", URL.createObjectURL(stream));
Globalvars.pc.addStream(stream);

if (isCaller){
Globalvars.pc.createOffer(getDescription, null, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });
}
else{
console.log("Got Remote Description");
console.log(Globalvars.pc.remoteDescription);
//Globalvars.pc.createAnswer(Globalvars.pc.remoteDescription, getDescription);
Globalvars.pc.createAnswer(getDescription, null, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });
}

function getDescription(desc) {
Globalvars.pc.setLocalDescription(desc);
console.log("my desc");
console.log(desc);
Globalvars.socket.emit("call", {"sdp": encodeURIComponent(desc.sdp), "type": desc.type, "receiver_id" : params.receiver_id, "caller_id" : params.caller_id});
//signalingChannel.send(JSON.stringify({ "sdp": desc }));
}
});
},
......

完整代码可在 https://bitbucket.org/ajaybc/meetchat-client 获得和 https://bitbucket.org/ajaybc/meetchat-server

最佳答案

你可能需要添加

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />

进入你的AndroidManifest.xml

我已验证 WebRTC 可与 https://download.01.org/crosswalk/releases/crosswalk/android/beta/7.36.154.12/ 一起使用和 https://apprtc.appspot.com/在我的 Nexus 5 上。

希望它对你有用。

关于javascript - WebRTC远程视频显示为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18913090/

27 4 0
文章推荐: javascript - 如何获取 px 维度的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com