我正在尝试使用 Agora.io WebSDK 从我的直播应用中播放直播。从流对象调用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);
});
感谢帮助!