Table of Contents
This tip is about the how to Build a Live Video Streaming iOS App with Agora 4.x SDK Preview. So read this free guide, How to Build a Live Video Streaming iOS App with Agora 4.x SDK Preview step by step. If you have query related to same article you may contact us.
How to Build a Live Video Streaming iOS App with Agora 4.x SDK Preview – Guide
Who wants to build a video chat app in an hour? This is a guide for how to Quickly and easily build a video chat application that can support multiple participants with the Agora SDK.
Requirements
Settings up the library Now with CocoaPods
segment ‘Your app’ do
pod ‘NowRtcEngine_iOS’, ‘3.4.0’
The end
Add Camera and microphone permissions
To use the microphone and camera, we will need to ask the user for permission to do this. In your Info.plist, add the following keys:
Privacy – Microphone usage description
Privacy – Camera Description of use
Be sure to add a value for each one. These values are user-facing and will be displayed when the app requests these permissions from the user.
Settings up the scene
In our Main.storyboard, we’ll need to add the views that Agora will use to display the video feeds. For our demo, we’ll use a single large view to display our local feed and a collection view to show an arbitrary number of remote users, but feel free to adjust as needed for your own needs.
The local view is in green and the remote view template is in red for easy identification. Add a View object to the local stream, a UIButton to mute and hang up the call, and a UICollectionView to hold the remote streams. Your UICollectionViewCells can be as simple as a single view to keep the flow going – in the example above I’ve added an overlay to show the remote username if we know it.
be sure to hook up the views in your main View Controller and set the View Controller as the UICollectionView delegate and dataSource:
View controller storyboard connections
and connect up your custom collection view cell:
Start engine now
To use the Agora engine, we need to create an instance of AgoraRtcEngineKit with our app ID.
First, we’ll need to retrieve our app ID by accessing the Agora Dashboard. If you haven’t created a Now project, do it now by clicking on “New Project”.
Once you have a project, click on the “Edit” button button (or open the Project Management panel) to view the details for that project. Copy the app ID and add it to your project. If you have activated the app certificate, you will also need a token to join channels – you can generate a temporary one by clicking “Generate temporary token”. You can also read our tutorial on how to generate your own tokens here.
The first call you make to Agora should be to launch a shared Agora engine. We’ll do this by creating a helper function that initializes the engine if we haven’t already done so, and will only return it if we’ve done so. That way we can call it whenever we need a reference to the engine, without having to worry about who does it first.
We will also need to implement the AgoraRtcEngineDelegate protocol so that we can respond to the relevant callbacks:
Enable Video
The next step is to tell Agora that we want the video enabled and where to place the local video stream. We can then call this function from our viewDidLoad().
join a channel
Once the engine is initialized, joining a call is as easy as calling joinChannel() in the Now engine.
Settings up Remote Video
Now is the time to put our UICollectionView to good use. We will maintain a list of remote user IDs and for each we will define up a remote video screen in our collection.
To get this list of user IDs (and maintain it), we will use the rtcEngine (didJoinedOfUid 🙂 and rtcEngine (didOfflineOfUid 🙂 callbacks. Inside your AgoraRtcEngineDelegate extension, add the following functions:
And with that, you have a working video chat app. Beware of audio feedback if you are testing on multiple devices at the same time.
Polish
There are a few more pieces we should add to make our app a little nicer. On the one hand, our buttons do not do anything. Let’s fix this first. muting button is a simple call to muteLocalAudioStream():
we can also hang up calling leaveChannel():
And we’re done! You can find the full app here. Thanks for following us and happy programming!
Final note
I hope you like the guide How to Build a Live Video Streaming iOS App with Agora 4.x SDK Preview. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.