Before you use Stringee Video Conference API to make a video conference:
Then, the best way to learn how to uses Stringee Video Conference API is to follow the following steps:
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.
Stringee Android SDK is distributed as an AAR and can be added to your project by referencing the AAR remotely with Maven.
allprojects {
repositories {
jcenter()
}
}
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile 'com.stringee.sdk.android:stringee-android-sdk:1.3.8'
}
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.** { *; }
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:
In the MainActivity class, declare a variable to store the access_token.
public class MainActivity extends AppCompatActivity {
private String token;
Next, we will connect to Stringee Server. You must do this before you can make or answer a call.
private StringeeClient client;
The StringeeClient class is defined in Stringee SDK. It includes methods interacting with Stringee Server.
client = new StringeeClient(this);
client.connect(token);
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, we want it to make a room:
private StringeeRoom mStringeeRoom;
mStringeeRoom = new StringeeRoom(MainActivity.client);
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) {
}
});
mStringeeRoom.makeRoom();
Then, a room chat is created on server and the client will connects to the room.
When the client connects to Stringee Server and a room chat has already created, we want the client to join the room:
mStringeeRoom = new StringeeRoom(MainActivity.client, {room id});
mStringeeRoom.joinRoom();
When the client connects to the room, we want it to publish local audio/video stream to the room:
StringeeStream stringeeStream = new StringeeStream(ConferenceCallActivity.this);
mStringeeRoom.publish(stringeeStream);
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);
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:
<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" />
private FrameLayout mLocalViewContainer;
private FrameLayout mRemoteViewContainer;
mLocalViewContainer = (FrameLayout) findViewById(R.id.v_local);
mRemoteViewContainer = (FrameLayout) findViewById(R.id.v_remote);
Before publishing or subscribing a stream, registering a StringeeStreamListener interface:
stringeeStream.setStreamListener(new StringeeStream.StringeeStreamListener() {
@Override
public void onStreamMediaAvailable(StringeeStream stringeeStream) {
}
});
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.
Leave a room and release resources:
mStringeeRoom.leaveRoom();
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