我正在尝试使用Agora.io WebSDK从我的直播应用中播放直播。从 stream 对象调用 play()方法时,流永远不会加载。出现视频大小的黑屏,但没有任何反应。从控制台看,似乎发生了加载/停止无限循环。在play方法之后,似乎重新加载并停止了:
Agora-SDK [DEBUG]: [1609713] play(). playdiv null AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [INFO]: [B50E2] Remote stream subscribed with uid 1609713 AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: start vsResHack
MediaStream { id: "PBbApFYHw8", active: true, onaddtrack: null, onremovetrack: null }
AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: [B50E2] Reload Player playdiv StreamId 1609713 AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: [1609713] Stop stream player with id 1609713 AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: destroy remote Player 1609713 AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: Media Player Status Change Triggered by destroy()
Object { type: "player-status-change", playerId: 0, mediaType: "video", status: "aborted", reason: "stop", isErrorState: false }
AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: Media Player Status Change Triggered by destroy()
Object { type: "player-status-change", playerId: 0, mediaType: "audio", status: "aborted", reason: "stop", isErrorState: false }
AgoraRTCSDK-2.9.0.js:2:3436
ErrState: [object Object] app_agoratest.html:60:37
The stream was suspended! app_agoratest.html:66:41
该流似乎再次尝试播放:
Agora-SDK [DEBUG]: Media Player Status Change
Object { type: "player-status-change", playerId: 7, mediaType: "video", status: "paused", reason: "suspend", isErrorState: true }
AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [DEBUG]: Media Player Status Change
Object { type: "player-status-change", playerId: 7, mediaType: "audio", status: "play", reason: "playing", isErrorState: false }
然后再次停止
Agora-SDK [DEBUG]: [1659733] Close stream with id 1609713 AgoraRTCSDK-2.9.0.js:2:3436
Agora-SDK [INFO]: [B50E2] Unsubscribe stream success AgoraRTCSDK-2.9.0.js:2:3436
ErrState: AbortError: The fetching process for the media resource was aborted by the user agent at the user's request. app_agoratest.html:60:37
Error playing the stream! app_agoratest.html:62:41
这无限循环地继续。如果有人遇到过此问题或类似问题,请多加提示,以防可能导致此问题的发生。我在Firefox和Chrome中都尝试了自己的代码。
这是我的初始化代码:
client = AgoraRTC.createClient({
mode: "live",
codec: "h264"
});
client.setClientRole("audience");
client.init(my_app_id, function () {
console.log("AgoraRTC client initialized");
}, function (err) {
console.log("AgoraRTC client init failed", err);
});
这是我播放流的代码:
client.join(null, room_number + "", uid, function (uid) {
client.on("stream-added", function (t) {
var i = t.stream;
client.subscribe(i, {
video: true,
audio: true
})
client.on("stream-subscribed", {
muted: "true"
}, function (e) {
var t = e.stream;
});
i.play("playdiv", function (errState) {
console.log("ErrState: " + errState);
if (errState.status !== "aborted") {
console.log("Error playing the stream!");
i.resume();
}
if (errState && errState.status !== "suspend") {
console.log("The stream was suspended!");
i.resume();
}
});
});
}, function (err) {
console.log("joining the room failed because: ", err);
});
感谢帮助!
答案 0 :(得分:0)
我发现了错误,我只是设置了错误的uid...。如果有人遇到此问题,请先进行检查。