1

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.

  • Are you using ExternalVideoInputService, the same way, the example you liked does? – Samyak Feb 26 '21 at 13:21
  • The example you linked has the following method: https://github.com/AgoraIO/API-Examples/blob/f2de857bdb3a49d381d955423220c36d2c167b8e/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java#L365. Are you creating the service the same way? – Samyak Feb 26 '21 at 14:43
  • Hi @Samyak, yes, I do. The service class defined here [ExternalVideoInputService](https://github.com/AgoraIO/API-Examples/blob/f2de857bdb3a49d381d955423220c36d2c167b8e/Android/APIExample/lib-switch-external-video/src/main/java/io/agora/advancedvideo/externvideosource/ExternalVideoInputService.java#L16) , is the same class I use. I start the service in a similar way as the example, like this: – Francis Anyeji Feb 28 '21 at 12:36
  • You'll find the code here [link](https://gist.github.com/Francis365/aebfa57fd0b2f49b8d3816f4fb91df38). You'll find the setVideoConfig() method defined, from the question above. I do receive log report that the service is started and the video stream is published to agora sdk. Then the screen share logo appears on the android device at the notification bar – Francis Anyeji Feb 28 '21 at 12:53
  • Rather than creating a texture view and using setLocalVideo, try to do what API-Examples is doing. They have the following file: https://github.com/AgoraIO/API-Examples/blob/3b3c443e44d759b3c125fed9988f00d792e0960e/Android/APIExample/lib-switch-external-video/src/main/java/io/agora/advancedvideo/externvideosource/screenshare/ScreenShareInput.java#L32. which is being used here https://github.com/AgoraIO/API-Examples/blob/3b3c443e44d759b3c125fed9988f00d792e0960e/Android/APIExample/lib-switch-external-video/src/main/java/io/agora/advancedvideo/externvideosource/ExternalVideoInputManager.java#L43 – Samyak Mar 02 '21 at 12:54
  • I thought that was not necessary too, if I don't set it, the last frame from camera freezes as I switch to share screen. I did implement the ScreenShareInput class just as the example. onVideoInitialized(target) method is called too on this class. Could this be that it's updating the video feed to a different thread? – Francis Anyeji Mar 02 '21 at 18:10
  • Yeah. ScreenShareInput should be rendering the feed inside the target surface when onVideoInitalized is called. Can you try using that and let me know if it works? – Samyak Mar 03 '21 at 15:08
  • Thanks for the suggestions @Samyak, I did use this class to start the screen record, I created a surface(i.e target), which is passed to the createVirtualDisplay found in ScreenShareInput. I also switched to use Agora push method to send the recorded data to the SDK, I did that from onFrameAvailable() found in ScreenShareInput class, but it's not working – Francis Anyeji Mar 04 '21 at 09:46
  • I enabled call encryption too, but I don't think that will cause this. I tried disabling it though, it still the same – Francis Anyeji Mar 04 '21 at 09:48
  • Is it possible for you to share the code? It's going to be hard to debug otherwise. – Samyak Mar 04 '21 at 18:02
  • I can share the code snippet, hope that will be helpful. This is the Agora helper class [AgoraHelper](https://gist.github.com/Francis365/658cbb6d13806699b2e6c87ad3c1f0cd) This is the Call Activity class [AgoraVideoCallActivity](https://gist.github.com/Francis365/51103124be0b3c8569bc526c01b9dc5c) Layout xml for the Call Activity [activity_agora_video_call2.xml](https://gist.github.com/Francis365/3b841c566ef6480da910a0a92e240432) This is the Screenshare class configured for video push mode [ScreenShareInput](https://gist.github.com/Francis365/7947b7afbe088999e94092da1ccfdf14) – Francis Anyeji Mar 06 '21 at 14:49
  • The custom videosource: [ExternalVideoInputManager](https://gist.github.com/Francis365/d1607602f6c2aa18ba043173b61ccc5a) The Screen Share Service class: [ExternalVideoInputService](https://gist.github.com/Francis365/a66e1ed836b9a4d8e19b64df5c2e349b) Hope, this is ok, thanks – Francis Anyeji Mar 06 '21 at 15:01
  • Hey, I'm having a hard time reproducing your error. Can you please make a minimum reproducible example as per Stackoverflow rules: https://stackoverflow.com/help/minimal-reproducible-example? Also can you check if the following example: https://github.com/AgoraIO/API-Examples/blob/master/Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java is working for you? It will help me know if this is an integration issue or something else. – Samyak Mar 11 '21 at 12:40

0 Answers0