Suggestions

close search

Getting started with Stringee Video Conference API using Android SDK

Step 1: Prepare

Before you use Stringee Video Conference API to make a video conference:

  1. Sign up for a Stringee account free here: https://developer.stringee.com/account/register
  2. Create a project on Stringee Dashboard.

Stringee create project

Then, the best way to learn how to uses Stringee Video Conference API is to follow the following steps:

Step 2: Creating a new project

Stringee SDK is designed to be used with Android Studio

1. Open Android Studio and select New Project from the File menu.
2. Set the minimum SDK for the app to be API 15 (Android 4.0.3 ICE_CREAM_SANDWICH).
3. Click through the wizard, ensuring that Empty Activity is selected. Leave the Activity Name set to MainActivity, and leave the Layout Name set to activity_main.

Step 3: Adding the Stringee SDK

Stringee Android SDK is distributed as an AAR and can be added to your project by referencing the AAR remotely with Maven.

  1. Navigate to your build.gradle at the project level and include the following:

Stringee jcenter

allprojects {
    repositories {
        jcenter()
    }
}
  1. Navigate to your build.gradle at the app level and include the following:

Stringee dependencies

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
dependencies {    
    compile 'com.stringee.sdk.android:stringee-android-sdk:1.3.8'
}

Step 4: Permissions and proguard

The Stringee Android SDK requires some permissions from your app's AndroidManifest.xml file:

// for internet access
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
// for audio access
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
// for camera access
<uses-permission android:name="android.permission.CAMERA" />

If your project uses ProGuard, you may have to add the following settings to the ProGuard configuration file to ensure Stringee builds correctly:

-dontwarn org.webrtc.**
-keep class org.webrtc.** { *; }
-keep class com.stringee.** { *; }

Step 5: Setting up authentication

In order to connect to Stringee Server, you will need access to the authentication credential: access4token. In a production application, the access_token should be generated by your server described here: Client authentication, but to speed things up we will just hard code the value for now:

  1. In the MainActivity class, declare a variable to store the access_token.

    public class MainActivity extends AppCompatActivity {
    
    private String token;
  2. Adjust the code by hard coding the value for the token:
    To do this, go to Dashboard -> Tools -> Generate Access token and generates an access_token.

Step 6: Connecting

Next, we will connect to Stringee Server. You must do this before you can make or answer a call.

  1. Add a StringeeClient property to the MainActivity class.
    private StringeeClient client;

    The StringeeClient class is defined in Stringee SDK. It includes methods interacting with Stringee Server.

  2. Instantiate the StringeeClient object and call its connect(token) method:
    client = new StringeeClient(this);
    client.connect(token);
  3. To interact with Stringee Server connection, you will need register a StringeeConnectionListener interface with StringeeClient object before connecting.

    client.setConnectionListener(new StringeeConnectionListener() {
    @Override
    public void onConnectionConnected(StringeeClient stringeeClient, boolean isReconnecting) {
    }
    
    @Override
    public void onConnectionDisconnected(StringeeClient stringeeClient, boolean isReconnecting) {
    
    }
    
    @Override
    public void onIncomingCall(StringeeClient stringeeClient, StringeeCallParam stringeeCallParam) {
    
    }
    
    @Override
    public void onConnectionError(StringeeClient stringeeClient, StringeeError stringeeError) {
    
    }
    
    @Override
    public void onRequestNewToken(StringeeClient client) {
    
    }
    
    @Override
    public void onCustomMessage(String from, JSONObject msg) {
    
    }
    });        
    • When the client connects to Stringee Server, the onConnectionDisconnected(StringeeClient stringeeClient, boolean isReconnecting) method is called.
    • When the client disconnects to Stringee Server, the onConnectionDisconnected(StringeeClient stringeeClient, boolean isReconnecting) method is called
    • When the client fails to connect to Stringee Server, the onConnectionError(StringeeClient stringeeClient, StringeeError stringeeError) method is called.
    • When the token is expired, the onRefreshToken(StringeeClient stringeeClient) is called. You will need re-generate a new token and connect again.
    • When the client receives an incoming call, the onIncomingCall(StringeeClient stringeeClient, StringeeCallParam stringeeCallParam) method is called.

Step 7: Making a room

When the client connects to Stringee Server, we want it to make a room:

  1. Create ConferenceCallActivity class to display the conference call screen.
  2. Add a mStringeeRoom property to the ConferenceCallActivity class:
    private StringeeRoom mStringeeRoom;
  3. Modify the implementation of the method onCreate in the ConferenceCallActivity class to include code to instantiate a StringeeRoom object:
    mStringeeRoom = new StringeeRoom(MainActivity.client);
  4. Register a StringeeRoomListener interface. This interface includes callback methods are called in response to room events:

    mStringeeRoom.setRoomListener(new StringeeRoomListener() {
    @Override
    public void onRoomConnected(StringeeRoom stringeeRoom) {
    
    }
    
    @Override
    public void onRoomDisconnected(StringeeRoom stringeeRoom) {
    
    }
    
    @Override
    public void onRoomError(StringeeRoom stringeeRoom, StringeeError stringeeError) {
    
    }
    
    @Override
    public void onStreamAdded(StringeeStream stringeeStream) {
    
    }
    
    @Override
    public void onStreamRemoved(StringeeStream stringeeStream) {
    
    }
    
    @Override
    public void onStreamPublished(StringeeStream stringeeStream, boolean isReconnecting) {
    
    }
    
    @Override
    public void onStreamPublishError(StringeeStream stringeeStream, StringeeError stringeeError, boolean isReconnecting) {
    
    }
    
    @Override
    public void onStreamUnPublished(StringeeStream stringeeStream) {
    
    }
    
    @Override
    public void onStreamUnPublishError(StringeeStream stringeeStream, StringeeError stringeeError) {
    
    }
    
    @Override
    public void onStreamSubscribed(StringeeStream stringeeStream, boolean isReconnecting) {
    
    }
    
    @Override
    public void onStreamUnSubscribed(StringeeStream stringeeStream) {
    
    }
    
    @Override
    public void onStreamSubscribeError(StringeeStream stringeeStream, StringeeError stringeeError, boolean isReconnecting) {
    
    }
    
    @Override
    public void onStreamUnSubscribeError(StringeeStream stringeeStream, StringeeError stringeeError) {
    
    }
    });
  5. Call the makeRoom() method to make a room chat:
    mStringeeRoom.makeRoom();

    Then, a room chat is created on server and the client will connects to the room.

    • When the client connects to the room, the onRoomConnected(StringeeRoom stringeeRoom) method is called
    • When the client fails to connect the room, the onRoomError(StringeeRoom stringeeRoom, StringeeError stringeeError) method is called.

Step 8: Joining a room

When the client connects to Stringee Server and a room chat has already created, we want the client to join the room:

  1. Instantiate a StringeeRoom object with room id:
    mStringeeRoom = new StringeeRoom(MainActivity.client, {room id});
  2. Register a StringeeRoomListener interface as Step 7.2.
  3. Call the joinRoom() method to join a room chat:
    mStringeeRoom.joinRoom();

Step 9: Publishing a stream

When the client connects to the room, we want it to publish local audio/video stream to the room:

  1. Modify the implementation of the onRoomConnected(StringeeRoom stringeeRoom) method to include code to instantiate a StringeeStream object:
    StringeeStream stringeeStream = new StringeeStream(ConferenceCallActivity.this);
  2. Call the publish() method to publish local stream to the room:
    mStringeeRoom.publish(stringeeStream);

Step 10: Subscribing a stream

Each time a client connects to the room, others will receive an event onStreamAdded(StringeeStream stringeeStream). We want clients to be able to subsribe to (view) other's streams: Modify the implementation of the onStreamAdded(StringeeStream stringeeStream) method to include code to subscribe a stream:

mStringeeRoom.subscribe(stringeeStream);

Step 11: Displaying local and remote video stream

The Stringee Android SDK exposes videos of streams as View objects. You can add these as children of ViewGroup objects in your app. This sample app will use FrameLayout objects (which extend ViewGroup) as containers for streams's views: When the client publish a video stream to the room, we want it to display video:

  1. Open the app/res/layout/activity_conference_call.xml file and include the following:
<FrameLayout
    android:id="@+id/v_remote"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<FrameLayout
    android:id="@+id/v_local"
    android:layout_width="80dp"
    android:layout_height="120dp"
    android:layout_alignParentRight="true"        
    android:layout_margin="10dp" />
  1. Declare mLocalViewContainer and mRemoteViewcontainer as properties of ConferenceCallActivity class.
    private FrameLayout mLocalViewContainer;
    private FrameLayout mRemoteViewContainer;
  2. Then, initialize these layout view objects
    mLocalViewContainer = (FrameLayout) findViewById(R.id.v_local);
    mRemoteViewContainer = (FrameLayout) findViewById(R.id.v_remote);
  3. Before publishing or subscribing a stream, registering a StringeeStreamListener interface:

    stringeeStream.setStreamListener(new StringeeStream.StringeeStreamListener() {
    @Override
    public void onStreamMediaAvailable(StringeeStream stringeeStream) {
    
    }
    });
  4. Modify the implementation of the onStreamMediaAvailable(StringeeStream stringeeStream) method to include code to display stream video:
    Local stream:
    runOnUiThread(new Runnable() {
    @Override
    public void run() {
        mLocalViewContainer.removeAllViews();
        mLocalViewContainer.addView(stream.getView());
        stream.renderView(true);
    }
    });
    Remote stream:
    runOnUiThread(new Runnable() {
    @Override
    public void run() {
        mRemoteViewContainer.removeAllViews();
        mRemoteViewContainer.addView(stream.getView());
        stream.renderView(false);
    }
    });

    onStreamMediaAvailable(StringeeStream stringeeStream) method runs in background thread. So in order to interact with UI components from this method, your code must run in UI thread.

Step 12: Leaving a room

Leave a room and release resources:

mStringeeRoom.leaveRoom();

Step 13: Running the app

Now that your code is complete, you can run the app with your device. You can view a completed version of this sample app on GitHub:https://github.com/stringeecom/android-sdk-samples/tree/master/ConferenceCallSample