Skip to content

Instantly share code, notes, and snippets.

@samyak-jain
Created November 23, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samyak-jain/ba44911f7c9b6ab4aa866fb4b464ac19 to your computer and use it in GitHub Desktop.
Save samyak-jain/ba44911f7c9b6ab4aa866fb4b464ac19 to your computer and use it in GitHub Desktop.
private fun initializeApplication() {
// We first initialize our RtcEngine. This object will be used to call our Agora related methods
try {
mRtcEngine = RtcEngine.create(baseContext, APP_ID, object : IRtcEngineEventHandler() {})
} catch (e: Exception) {
Log.e(LOG_TAG, Log.getStackTraceString(e))
}
// By Default, Video is disabled. So we enable that.
mRtcEngine!!.enableVideo()
// We set some standard configuration like resolution, FPS and bitrate of the video
mRtcEngine!!.setVideoEncoderConfiguration(VideoEncoderConfiguration(VideoEncoderConfiguration.VD_640x360,
VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15,
VideoEncoderConfiguration.STANDARD_BITRATE,
VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT))
// All videos will be rendered on a SurfaceView.
// We are first fetching a reference to the FrameLayout we have defined in the XML
// We are then using Agora to create a SurfaceView object
// We are then adding this SurfaceView as a child to the FrameLayout
// And then, we are passing the SurfaceView to Agora so that it can render our local video on it
val localContainer = findViewById<FrameLayout>(R.id.local_container)
val localFrame = RtcEngine.CreateRendererView(baseContext)
localContainer.addView(localFrame, FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
mRtcEngine!!.setupLocalVideo(VideoCanvas(localFrame, VideoCanvas.RENDER_MODE_HIDDEN, 0))
// We are calling this method to join the Agora Channel
// We are passing in token. If it is empty, we are passing in null as the token
mRtcEngine!!.joinChannel(if (TOKEN.isEmpty()) null else TOKEN, CHANNEL, "", 0)
// This method allows us to fallback to low resolution and low bitrate
mRtcEngine!!.enableDualStreamMode(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment