I’m making an attempt to combine WebRTC Video into my iOS app. I downloaded the framework from https://webrtc.github.io/webrtc-org/native-code/ios/ and constructed it efficiently. Nevertheless, GLView shouldn’t be supported on this codebase, so I had to make use of MetalKit and added RTCMTLVideoView to my class. I additionally added RTCVideoRenderer and RTCVideoViewDelegate and set self.metalVideoView.delegate = self.
When the strategy to deal with incoming video is known as, I can see that the article obtained from the notification is RTC_OBJC_TYPE(RTCMediaStreamTrack): video janusv0 enabled Dwell, and VideoTracks depend is: 1. Nevertheless, I’m not capable of see any video on the display. As a substitute, I simply see a clean display. Within the earlier model of WebRTC, I used GLView with the identical implementation and it labored high-quality.
Are you able to please assessment my implementation under and let me know if I’m lacking something?
@objc func handleFloorPlanVideoReceived(_ notification: Notification?) {
if let remoteVideoTrack = notification?.object as? RTCVideoTrack {
print("Recieved Distant Video: (remoteVideoTrack)")
DispatchQueue.important.async {
// Initialize the metalVideoView
self.metalVideoView = RTCMTLVideoView(body: 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
// Arrange auto structure 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(fashion: .giant)
activityIndicator.colour = .white
self.metalVideoView.addSubview(activityIndicator)
self.activityIndicator = activityIndicator
// Arrange constraints for the exercise 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 shut button
let closeButton = UIButton(sort: .system)
if let closeImage = UIImage(systemName: "xmark") {
closeButton.setImage(closeImage, for: .regular)
}
self.metalVideoView.addSubview(closeButton)
// Arrange constraints for the shut 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 goal for shut button faucet occasion
closeButton.addTarget(self, motion: #selector(self.closeButtonTapped), for: .touchUpInside)
self.metalVideoView.setNeedsLayout()
}
}
}