Overview
It's finally time to bring everything together and display live streaming video in our app. Don't worry, it's easier than you think.
Here's what you need to do:
-
Create an HMSVideoView object in your view hierarchy. This is a subclass of UIView, so add it to your UI just like any other view, using Storyboard, XIB or in-code.
-
Get a reference to a video track object, specifically an HMSVideoTrack or one of its subclasses (for example HMSLocalVideoTrack). For example, the local peer's video track can be accessed like this:
let track = hmsSDK.localPeer?.videoTrack
- Connect the video track to the video view using the setVideoTrack method of HMSVideoView:
let videoView = HMSVideoView() videoView.frame = CGRect(x: 0, y: 0, width: 100, height: 100) ... videoView.setVideoTrack(track) // videoView is HMSVideoView, track is HMSVideoTrack
That's it. The video transmitted by the peer will now be displayed and start playing in your video view. 🥳
Remember, it's all about connecting the Video Track to the Video View. You'll be doing this often.