【发布时间】:2020-12-29 01:01:11
【问题描述】:
我正在尝试动态创建频道并发布,但它没有在受众应用程序上发送流
下面是代码sn-p
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, info: nil, uid: userID) { [weak self] (sid, uid, 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
【问题讨论】:
标签: swift live-streaming agora.io