Ant-Media-Server icon indicating copy to clipboard operation
Ant-Media-Server copied to clipboard

Use system audio in Screen Share with Android WebRTC SDK

Open SelimEmre opened this issue 4 years ago • 20 comments

I want to use system audio in a screen share. Android WebRTC SDK uses microphone audio by default.

Ticket ID: 38666

SelimEmre avatar Feb 10 '21 11:02 SelimEmre

Hi Selim,

Have you found anything to achieve this?

thinkgopal avatar Mar 01 '21 04:03 thinkgopal

Thank you for follow up @thinkgopal.

There is no update about this issue. Do you have any chance to help us? So that we can create a quick solution for you. Do you know if Android allows an application to capture the System Audio and having some references/links?

mekya avatar Mar 01 '21 09:03 mekya

@mekya Based on stackoverflow threads, some are telling it's possible to record internal audio of Android device. Please check below links for reference. https://stackoverflow.com/questions/17676142/record-android-audio-output https://www.androidpolice.com/2020/06/07/record-audio-android-apps/

thinkgopal avatar Mar 20 '21 07:03 thinkgopal

Yeah it seems that there is a support with Android 10.

Thank you. We can put this request to our roadmap. Let me plan when we can make it.

mekya avatar Mar 22 '21 09:03 mekya

Yeah it seems that there is a support with Android 10.

Thank you. We can put this request to our roadmap. Let me plan when we can make it.

Hi @mekya, what is the progress on it. I am using latest ant media Android sample app and It isn't using system audio.

ghost avatar May 16 '23 10:05 ghost

Hi @prabhat-oodles ,

Thank you for follow up. AFAIK it is implemented and should be working. On the other hand, this issue is still open. It seems that there is a confusion somewhere.

I'm putting it on the week's schedule to check it if we have some availability.

mekya avatar May 22 '23 08:05 mekya

Hi @prabhat-oodles ,

Thank you for follow up. AFAIK it is implemented and should be working. On the other hand, this issue is still open. It seems that there is a confusion somewhere.

I'm putting it on the week's schedule to check it if we have some availability.

Hi @mekya, I have downloaded the latest sample and using Samsung M31 (Android 13) device to test it. But, I am unable to stream my device audio. Only the sound from my mic is getting streamed when I share screen. Kindly check the current implementation.

PS: I forgot to mention that I am facing this issue when I try to switch from camera to Screen Capture while live streaming. If I start the stream using the share screen feature then the device audio is streaming fine.

ghost avatar May 22 '23 09:05 ghost

Thank you @prabhat-oodles for the update

mekya avatar May 22 '23 09:05 mekya

Thank you @prabhat-oodles for the update

Hi @mekya I have edited my above comment for more information.

PS: I forgot to mention that I am facing this issue when I try to switch from camera to Screen Capture while live streaming. If I start the stream using the share screen feature then the device audio is streaming fine.

ghost avatar May 22 '23 09:05 ghost

Hi @prabhat-oodles,

Thank you for the update. My colleague, @lastpeony, is going to work on this issue in this week.

@lastpeony , please pay attention to the @prabhat-oodles comment above.

Take care Oguz

mekya avatar May 22 '23 14:05 mekya

Mentioned PR feature enables switching of audio sources during streaming. When a user transitions from using the camera to screen sharing, the audio recording automatically switches from the microphone to system audio. Likewise, when transitioning from screen sharing back to the camera, the audio seamlessly switches back from system audio to the microphone.

lastpeony avatar May 24 '23 11:05 lastpeony

Hi @lastpeony. What is the latest update on the above issue? It is still showing in progress.

ghost avatar Jun 20 '23 11:06 ghost

Hi @prabhat-oodles Good news! The reported issue has been resolved, and the desired feature has been successfully implemented. You can begin utilizing it by checking out the branch associated with this pull request: GitHub Link. The changes from this branch will soon be merged into the master branch.

lastpeony avatar Jun 20 '23 12:06 lastpeony

Hi @lastpeony, downloaded code from your branch and added it in my project. Received below error while starting the stream.

java.lang.AssertionError: Expected condition to be true at org.webrtc.audio.WebRtcAudioEffects.assertTrue(WebRtcAudioEffects.java:194) at org.webrtc.audio.WebRtcAudioEffects.enable(WebRtcAudioEffects.java:109) at org.webrtc.audio.WebRtcAudioRecord.initRecording(WebRtcAudioRecord.java:333) --------- beginning of crash

Fatal error in: gen/jni_headers/sdk/android/generated_metrics_jni/../../../../../../../sdk/android/src/jni/jni_generator_helper.h, line 94

last system error: 0

Check failed: !env->ExceptionCheck()

Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 12276 (worker_thread -), pid 9871

Stream crashed after this error

ghost avatar Jun 20 '23 13:06 ghost

Hi @prabhat-oodles I just checked out the branch again and launched ScreenCaptureActivity I was able to succesfully use the new feature. Did you check the changes on ScreenCaptureActivity and modified your own applications activity acordingly?

lastpeony avatar Jun 20 '23 18:06 lastpeony

Hi @prabhat-oodles I just checked out the branch again and launched ScreenCaptureActivity I was able to succesfully use the new feature. Did you check the changes on ScreenCaptureActivity and modified your own applications activity acordingly?

Hi @lastpeony , I have made changes to my own app and also ran the sample at my end. In both scenarios, the streaming is also crashing with the same above error. Do I need to do anything else at my end other than the changes in the ScreenCaptureActivity?

ghost avatar Jun 21 '23 04:06 ghost

Hi @lastpeony ,

effects.enable(audioRecord.getAudioSessionId());

The above line is getting called twice in WebRtcAudioRecord.java. Once inside createAudioRecord() and then again inside initRecording() function. On second call, the assertion inside effects.enable() fails with above error.

This could be the issue, could you please check it at your end?

ghost avatar Jun 21 '23 04:06 ghost

@prabhat-oodles I just reproduced and will update you soon.

lastpeony avatar Jun 21 '23 10:06 lastpeony

@prabhat-oodles Could please check it again? I sent a fix and tested it on Android 13 emulator. When i switch to screen share it shares system audio and when i switch back to cameras it shares microphone audio.

lastpeony avatar Jun 21 '23 11:06 lastpeony

@prabhat-oodles Could please check it again? I sent a fix and tested it on Android 13 emulator. When i switch to screen share it shares system audio and when i switch back to cameras it shares microphone audio.

Thanks for quick response @lastpeony. I will check it and let you know. In the meantime, you can check another issue if possible. The streaming also crashes if we switch camera and share screen before starting the stream and then start. It gives the error - Could not register audio record policy

ghost avatar Jun 21 '23 11:06 ghost