Skip to content

Commit 165f3d7

Browse files
author
xianing
committed
support publish player and camera video track simultaneously
1 parent ff6bba7 commit 165f3d7

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

iOS/APIExample/Examples/Advanced/MediaPlayer/MediaPlayer.swift

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,33 +143,30 @@ class MediaPlayerMain: BaseViewController, UITextFieldDelegate {
143143
videoCanvas.sourceType = .mediaPlayer
144144
videoCanvas.sourceId = mediaPlayerKit.getMediaPlayerId()
145145
agoraKit.setupLocalVideo(videoCanvas)
146-
// agoraKit.startPreview()
147-
// start joining channel
148-
// 1. Users can only see each other after they join the
149-
// same channel successfully using the same app id.
150-
// 2. If app certificate is turned on at dashboard, token is needed
151-
// when joining channel. The channel name and uid used to calculate
152-
// the token has to match the ones used for channel join
153-
let option = AgoraRtcChannelMediaOptions()
154-
option.publishCameraTrack = .of(false)
155-
option.publishScreenTrack = .of(false)
156-
option.publishCustomVideoTrack = .of(false)
157-
option.publishEncodedVideoTrack = .of(false)
158-
option.publishMediaPlayerVideoTrack = .of(true)
146+
let option1 = AgoraRtcChannelMediaOptions()
147+
option1.publishMediaPlayerVideoTrack = .of(true)
148+
option1.publishMediaPlayerAudioTrack = .of(true)
149+
option1.publishAudioTrack = .of(true)
150+
option1.autoSubscribeAudio = .of(true)
151+
option1.autoSubscribeVideo = .of(false)
152+
option1.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
153+
option1.publishMediaPlayerId = .of((Int32)(mediaPlayerKit.getMediaPlayerId()))
154+
let connectionIdPointer = UnsafeMutablePointer<UInt>.allocate(capacity: MemoryLayout<UInt32>.stride)
155+
let result1 = agoraKit.joinChannelEx(byToken: KeyCenter.Token, channelId: channelName, uid: 1001, connectionId: connectionIdPointer, delegate: self, mediaOptions: option1, joinSuccess: nil)
159156

160-
option.publishMediaPlayerAudioTrack = .of(true)
161-
option.publishAudioTrack = .of(true)
162-
option.autoSubscribeAudio = .of(true)
163-
option.autoSubscribeVideo = .of(false)
164-
option.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
165-
option.publishMediaPlayerId = .of((Int32)(mediaPlayerKit.getMediaPlayerId()))
166-
let result = agoraKit.joinChannel(byToken: KeyCenter.Token, channelId: channelName, uid: 0, mediaOptions: option)
167-
if result != 0 {
157+
let option2 = AgoraRtcChannelMediaOptions()
158+
option2.publishCameraTrack = .of(true)
159+
option2.autoSubscribeAudio = .of(false)
160+
option2.autoSubscribeVideo = .of(false)
161+
option2.clientRoleType = .of((Int32)(AgoraClientRole.broadcaster.rawValue))
162+
let connectionIdPointer2 = UnsafeMutablePointer<UInt>.allocate(capacity: MemoryLayout<UInt32>.stride)
163+
let result2 = agoraKit.joinChannelEx(byToken: KeyCenter.Token, channelId: channelName, uid: 1002, connectionId: connectionIdPointer2, delegate: self, mediaOptions: option2, joinSuccess: nil)
164+
if result1 != 0 && result2 != 0 {
168165
// Usually happens with invalid parameters
169166
// Error code description can be found at:
170167
// en: https://docs.agora.io/en/Voice/API%20Reference/oc/Constants/AgoraErrorCode.html
171168
// cn: https://docs.agora.io/cn/Voice/API%20Reference/oc/Constants/AgoraErrorCode.html
172-
self.showAlert(title: "Error", message: "joinChannel call failed: \(result), please check your params")
169+
self.showAlert(title: "Error", message: "joinChannel call failed: \(result1), please check your params")
173170
}
174171
}
175172

0 commit comments

Comments
 (0)