我正在尝试将WebRTC视频集成到我的iOS应用程序中。我从https://webrtc.github.io/webrtc-org/native-code/ios/下载了源代码并成功构建了它。然而,GLView在这个代码库中不受支持,所以我不得不使用MetalKit并将RTCMTLVideoView添加到我的类中。我还添加了RTCVideoRenderer和RTCVideoViewDelegate,并设置self.metalVideoView.delegate = self。
当调用处理传入视频的方法时,我可以看到从通知中接收到的对象是RTC_OBJC_TYPE(RTCMediaStreamTrack):video janusv0 enabled Live,VideoTracks计数为:1.然而,我无法在屏幕上看到任何视频。我只看到一个空白的屏幕。在WebRTC的上一个版本中,我使用了GLView和相同的实现,它工作得很好。
您能在下面查看我的实现,并让我知道我是否遗漏了什么吗?
@objc func handleFloorPlanVideoReceived(_ notification: Notification?) {
if let remoteVideoTrack = notification?.object as? RTCVideoTrack {
print("Recieved Remote Video: \(remoteVideoTrack)")
DispatchQueue.main.async {
// Initialize the metalVideoView
self.metalVideoView = RTCMTLVideoView(frame: CGRect.zero)
self.metalVideoView.delegate = self
// Add the metalVideoView to the view hierarchy
self.view.addSubview(self.metalVideoView)
self.metalVideoView.backgroundColor = .edgeGray
self.metalVideoView.videoContentMode = .scaleAspectFit
// Set up auto layout constraints
self.metalVideoView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
self.metalVideoView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
self.metalVideoView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
self.metalVideoView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
self.metalVideoView.heightAnchor.constraint(equalTo: self.view.heightAnchor, multiplier: 1.0/3.0)
])
remoteVideoTrack.add(self.metalVideoView)
// Create and add the UIActivityIndicatorView
let activityIndicator = UIActivityIndicatorView(style: .large)
activityIndicator.color = .white
self.metalVideoView.addSubview(activityIndicator)
self.activityIndicator = activityIndicator
// Set up constraints for the activity indicator
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
activityIndicator.centerXAnchor.constraint(equalTo: self.metalVideoView.centerXAnchor),
activityIndicator.centerYAnchor.constraint(equalTo: self.metalVideoView.centerYAnchor)
])
activityIndicator.startAnimating()
// Create and add the close button
let closeButton = UIButton(type: .system)
if let closeImage = UIImage(systemName: "xmark") {
closeButton.setImage(closeImage, for: .normal)
}
self.metalVideoView.addSubview(closeButton)
// Set up constraints for the close button
closeButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
closeButton.topAnchor.constraint(equalTo: self.metalVideoView.topAnchor, constant: 8),
closeButton.trailingAnchor.constraint(equalTo: self.metalVideoView.trailingAnchor, constant: -8)
])
// Add target for close button tap event
closeButton.addTarget(self, action: #selector(self.closeButtonTapped), for: .touchUpInside)
self.metalVideoView.setNeedsLayout()
}
}
}
1条答案
按热度按时间nszi6y051#
我发现了一个问题。这是服务器端的一个打印错误。它说:“pachetization-mode-”而不是SDP中的“packetization-mode=”。它与旧的WebRTC框架一起工作,因为它有默认参数,并且可能忽略了这个错字。