如何解决无法通过liveBroadcasting中新创建的频道进行流式传输
我正在尝试动态创建一个频道并发布,但它并未在受众群体应用程序上发送流
下面是代码段
func setUpVideo() {
getAgoraEngine().enableVideo()
getAgoraEngine().enableAudio()
getAgoraEngine().setChannelProfile(.liveBroadcasting)
//Warning: only enable dual stream mode if there will be more than one broadcaster in the channel
//getAgoraEngine().enableDualStreamMode(true)
if isBroadcaster{
let videoCanvas = AgoraRtcVideoCanvas()
videoCanvas.uid = userID
videoCanvas.view = localVideoView
videoCanvas.renderMode = .fit
getAgoraEngine().startPreview()
getAgoraEngine().muteLocalAudioStream(false)
getAgoraEngine().muteLocalVideoStream(false)
getAgoraEngine().setClientRole(.broadcaster)
getAgoraEngine().setupLocalVideo(videoCanvas)
}
else{
getAgoraEngine().setClientRole(.audience)
getAgoraEngine().muteLocalAudioStream(true)
getAgoraEngine().muteLocalVideoStream(true)
}
//Configuration
getAgoraEngine().setVideoEncoderConfiguration(
AgoraVideoEncoderConfiguration(
size: AgoraVideoDimension640x480,frameRate: .fps30,bitrate: AgoraVideoBitrateStandard,orientationMode: .adaptative
)
)
}
```
```
func joinChannel() {
let options = AgoraRtcChannelMediaOptions()
options.autoSubscribeAudio = true
options.autoSubscribeVideo = true
if (rtcChannel != nil) {
rtcChannel.destroy()
}
rtcChannel = getAgoraEngine().createRtcChannel("Test123213")
rtcChannel.setRtcChannelDelegate(self)
rtcChannel.publish()
let success = rtcChannel.join(byToken: nil,info: nil,uid: 0,options: options)
print(success)
//APPROACH FROM https://docs.agora.io/en/Interactive%20Broadcast/start_live_ios?platform=iOS
/*if let name = userName {
let channelCode = getAgoraEngine().joinChannel(byUserAccount: name,token: tempToken,channelId: channelName) { [weak self] (sid,uid,elapsed) in
//TODO: Hardik : Call API HERE for join
self?.userID = uid
}
print("RTC---",channelCode)
} else {
let channelCode = getAgoraEngine().joinChannel(byToken: tempToken,channelId:channelName,uid: userID) { [weak self] (sid,elapsed) in
//TODO: Hardik : Call API HERE for join
self?.userID = uid
}
print("RTC---",channelCode)
}*/
}
extension AgoraVideoViewController: AgoraRtcChannelDelegate {
func rtcChannelDidJoin(_ rtcChannel: AgoraRtcChannel,withUid uid: UInt,elapsed: Int) {
if !isBroadcaster{
let videoCanvas = AgoraRtcVideoCanvas()
videoCanvas.uid = uid
videoCanvas.view = localVideoView
videoCanvas.renderMode = .fit
getAgoraEngine().setupRemoteVideo(videoCanvas)
}
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel,didJoinedOfUid uid: UInt,elapsed: Int) {
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel,didOfflineOfUid uid: UInt,reason: AgoraUserOfflineReason) {
}
func rtcChannelDidLeave(_ rtcChannel: AgoraRtcChannel,with stats: AgoraChannelStats) {
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel,didOccurWarning warningCode: AgoraWarningCode) {
}
func rtcChannel(_ rtcChannel: AgoraRtcChannel,didOccurError errorCode: AgoraErrorCode) {
}
}
回调到达rtcChannelDidJoin,但是观众角色无法看到远程视频。但是,两个角色都可以加入渠道。 createRtcChannel 返回两个角色的 0:成功
任何人都可以建议正确的做法吗?我的要求是在主机加入频道后立即创建频道。 参考:
https://docs.agora.io/en/Interactive%20Broadcast/start_live_ios?platform=iOS https://github.com/AgoraIO-Usecase/Breakout-Class/blob/master/breakout-ios/AgoraDualChannels/AgoraDualChannels/Controllers/LiveRoomViewController.swift
解决方法
rtcChannelDidJoin
是本地用户成功加入频道时收到的回调。您需要改为在didJoinedOfUid
中设置远程视频,这是当远程用户加入时收到的回叫。对于听众来说,广播公司是远程用户,而不是本地用户。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。