Audio/Video Broadcast

To use Audio/Video broadcast functionality, you must download Audio/Video chat enabled Xamarin SDK. To start using it’s functionality you must have AVBroadcast instance which can be obtained as follows:

<codeAVBroadcast avbroadcast = new AVBroadcast (this.ApplicationContext);

Note that the broadcast feature is available for One-on-One chat.
1. Sending broadcast request
Before starting broadcast, you have to send the request to another user. To send the broadcast use SendAVBroadcastRequest() function. The syntax for this function is as follows:

SendAVBroadcastRequest(String toId, Callbacks callbacks)


avbroadcast.SendAVBroadcastRequest("15",new MyCallback(successObj=>this.onSucess(successObj)));

Where MyCallback is as follows :

class MyCallback : Java.Lang.Object, ICallback{
     Action <Org.Json.JSONObject> _onSuccess;
     Action <Org.Json.JSONObject> _onFail;
     public MyCallback(Action<Org.Json.JSONObject> onSuccess, Action<Org.Json.JSONObject> onFail = null)
	this._onFail = onFail;
	this._onSuccess = onSuccess;
      void SuccessCallbac(JSONObject){...}
      void FailCallback(JSONObject){...}

The success response will be as follows:


The response will contain the id of user to whom you have sent the request, and the callid which is unique id assigned for each Audio Video Broadcast call, so that there will be no cross connection.

2. Start broadcast
Once you sent the request successfully or someone has sent you the request, you can start the broadcast by using StartBroadcast() function. The syntax for this function is as follows:

StartBroadcast(boolean isInitiator, String callid, RelativeLayout container,Callbacks callbacks)

The description of parameters is as follows:
isInitiator: You have to specify your role in the broadcast. If you are the broadcaster so you will pass true, so your audio and video will be broadcasted, and if you are the listener of broadcast then pass false, so your audio and video will not be broadcasted, you will receive the broadcaster’s audio and video.
callid: This is the call id you get from sending the request, or in the request someone sent to you.
container: Container is the relative layout in which video will be displayed

3. Invite other users to the broadcast
You can invite other users in the broadcast going on. To do so use InviteUsersInBroadcast() function. The syntax for this function is as follows:

InviteUsersInBroadcast(JSONArray users, String callid, Callbacks callbacks)


JSONArray user = new JSONArray ();
user.Put (1);
user.Put (2);
avbroadcast.InviteUsersInBroadcast(user,new MyCallback(successObj=>this.onSucess(successObj)));

4. End broadcast
In order to end the broadcast use EndBroadcast() function. The syntax for this fnuction is as follows:

EndBroadcast(boolean isInitiator, String userId, String callid, Callbacks callbacks)

The description for the parameters is as follows:
isInitiator: If you are broadcaster then pass true, so the broadcast will end for all the users, if you are listener then pass false, so the broadcast will not end for all the users, you will just leave the broadcast.
userid: Pass the user id of the user you are having the broadcast with.
callid: Pass the call id of this broadcast which you receive from the request you sent or the request you receive.


avbroadcast.EndBroadcast(true,"15","b7054a443b7eb3f539c01333f0d96904",new MyCallback(successObj=>this.onSucess(successObj)));

5. Rotation handling
As you know Android devices are sensitive to the rotation, you need to handle the rotation specially while having broadcast, so that you don’t find any difficulties and have smooth transition while rotating the device. You need to use following function to do so:


Pass the container which you have used in the function startBroadcast() function.

Not finding what you need?

The CometChat team is here to help!