[英]render video tracks of existing participants
So I connect to a room, which might already have existing participants sharing their videos. 因此,我连接到一个会议室,该会议室可能已经有现有的参与者共享他们的视频。 However when I try to iterate through all the participants and add their respective videos...it doesn't work.
但是,当我尝试遍历所有参与者并添加他们各自的视频时,它不起作用。 For some reason, even though the participant count is not 0. How do I get the video tracks of all the existing participants in a room and render them?
由于某些原因,即使参与者计数不为0。如何获取房间中所有现有参与者的视频轨道并进行渲染?
So basically this is the workflow: 所以基本上这是工作流程:
Here is my code for the didConnect() delegate which fires when one enters a room.the addVideoTrack function renders the video for any new participants, so its working fine, but I want to do it for previously existing participants. 这是我的didConnect()委托的代码,当有人进入房间时会触发该代码。addVideoTrack函数可为任何新参与者呈现视频,因此它可以正常工作,但我想对以前已有的参与者进行处理。
func didConnect(to room: TVIRoom) {
connectedParticipants = room.participants
for participant in connectedParticipants {
for videoTrack in participant.videoTracks {
addVideoTrack(videoTrack:videoTrack)
}
}
changeRoomLabel(messageText: "Room: \(room.name)")
}
Twilio developer evangelist here. Twilio开发人员布道者在这里。
When you connect to the room and find the participants, you may not have connected to their media streams yet. 当您连接到会议室并找到参与者时,您可能尚未连接到他们的媒体流。 Instead, you should implement the
TVIParticipantDelegate
. 相反,您应该实现
TVIParticipantDelegate
。 As you can see in the Twilio Video quickstart application (which only handles one external participant, but is a good example), when connecting to a room set the controller as the participant's delegate: 正如您在Twilio Video快速入门应用程序 (仅处理一个外部参与者,但是一个很好的示例)中看到的那样,当连接到会议室时,将控制器设置为参与者的代表:
func didConnect(to room: TVIRoom) {
if (room.participants.count > 0) {
self.participant = room.participants[0]
self.participant?.delegate = self
}
}
Then, the example implements the TVIParticipantDelegate
participant:addedVideoTrack
to render the video once it is added to the participant: 然后,该示例实现
TVIParticipantDelegate
participant:addedVideoTrack
以在将视频添加到参与者后呈现该视频:
extension ViewController : TVIParticipantDelegate {
func participant(_ participant: TVIParticipant, addedVideoTrack videoTrack: TVIVideoTrack) {
logMessage(messageText: "Participant \(participant.identity) added video track")
if (self.participant == participant) {
setupRemoteVideoView()
videoTrack.addRenderer(self.remoteView!)
}
}
}
And the other delegate methods here . 还有其他的委托方法 。
Let me know if that helps at all. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.