I'm using Agora Android native sdk 3.3.0. I made a reference to this project SwitchCameraScreenShare
I get a black screen/(no video frame update), when I switch the sdk video source (using mRtcEngine.setVideoSource(screenShareVideoSource)
) to the screensharing video source. When I switch back to default video source (i.e: AgoraDefaultSource class) like this mRtcEngine.setVideoSource(AgoraDefaultSource())
, the camera comes back.
This is the video source I use for screen share: ExternalVideoInputManager. This is the actual screen share input from android MediaProjectionManager: ScreenShareInput.
I think the problem is how I start the screen share. Before I start the screen share service (I use android Service), I first initialise the SDK, then join a channel, like below:
fun initializeAgoraEngine(context: Context) {
try {
appId = context.getString(R.string.agora_app_id)
mRtcEngine = RtcEngine.create(context, appId, this)
} catch (e: Exception) {
throw RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e))
}
setupVideoProfile()
agoraEvents?.onAgoraInitialized()
}
private fun setupVideoProfile() {
mRtcEngine!!.enableVideo()
mRtcEngine!!.setVideoEncoderConfiguration(VideoEncoderConfiguration(VideoEncoderConfiguration.VD_640x360,
VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15,
VideoEncoderConfiguration.STANDARD_BITRATE,
ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT))
}
Then after I start screen share service and set the screen share video source, I remove the old video textureview, from the video FrameLayout view, then set a new one, like this:
if (binding.myVideoview.childCount > 0) {
binding.myVideoview.removeAllViews()
}
val textureView = RtcEngine.CreateTextureView(this)
binding.myVideoview.addView(textureView)
AgoraHelper.setLocalVideo(textureView)
But it shows black screen, the video frame on the other device connected to the channel freezes, I've granted permissions for CAMERA, AUDIO-RECORD. Please help me know what i'm doing wrong, thanks.