Android Video Chat App Using Firebase
A video I made about how to create a video chat application using Firebase and Agora.IO SDK for Android.
Resources For Development
Dependency
compile 'io.agora.rtc:full-sdk:2.2.0'
Agora Video Streaming SDK
Download here.
XML Layout
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.aye.chat.Test.FireVideo"> <FrameLayout android:id="@+id/remote_video_view_container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" /> <FrameLayout android:id="@+id/local_video_view_container" android:layout_width="160dp" android:layout_height="200dp" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginEnd="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" android:background="@android:color/darker_gray" /> </RelativeLayout>
Java Class
public class FireVideo extends AppCompatActivity {
private RtcEngine mRtcEngine;
private IRtcEngineEventHandler mRtcEventHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fire_video);
mRtcEventHandler = new IRtcEngineEventHandler() {
@Override
public void onFirstRemoteVideoDecoded(int uid, int width, int height, int elapsed) {
Log.i("uid video",uid+"");
runOnUiThread(new Runnable() {
@Override
public void run() {
setupRemoteVideo(uid);
}
});
}
};
initializeAgoraEngine();
}
private void initializeAgoraEngine() {
try {
mRtcEngine = RtcEngine.create(getBaseContext(), getString(R.string.agora_app_id), mRtcEventHandler);
joinChannel();
setupLocalVideo();
setupVideoProfile();
} catch (Exception e) {
e.printStackTrace();
}
}
private void setupVideoProfile() {
mRtcEngine.enableVideo();
mRtcEngine.setVideoProfile(Constants.VIDEO_PROFILE_360P, false);
}
private void setupLocalVideo() {
FrameLayout container = (FrameLayout) findViewById(R.id.local_video_view_container);
SurfaceView surfaceView = RtcEngine.CreateRendererView(getBaseContext());
surfaceView.setZOrderMediaOverlay(true);
container.addView(surfaceView);
mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_ADAPTIVE, 0));
}
private void joinChannel() {
mRtcEngine.joinChannel(null, "aye", "Extra Optional Data", new Random().nextInt(10000000)+1); // if you do not specify the uid, Agora will assign one.
}
private void setupRemoteVideo(int uid) {
FrameLayout container = (FrameLayout) findViewById(R.id.remote_video_view_container);
if (container.getChildCount() >= 1) {
return;
}
SurfaceView surfaceView = RtcEngine.CreateRendererView(getBaseContext());
container.addView(surfaceView);
mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_ADAPTIVE, uid));
surfaceView.setTag(uid);
}
private void leaveChannel() {
mRtcEngine.leaveChannel();
}
}
Required Manifest Permissions
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.BLUETOOTH" />
Got any questions? Comment below ❤️
How did you connected this agora with firebase? can you tell me ?