sndcpy icon indicating copy to clipboard operation
sndcpy copied to clipboard

How to capture audio from restricted apps?

Open MC-dusk opened this issue 4 years ago • 18 comments

Thank U for the nice job. I can get audio from twitter, youtube, VLC and QQmusic successfully. But when I use NetEase CloudMusic, Clash of Clans, I can't hear anything on PC. I know that it's because of Apps restrictions. But I really want to get audio from those apps, what can I do? Is this project can't solve the problem and I should look for another method or program?

MC-dusk avatar Feb 01 '21 04:02 MC-dusk

You can't. Android decided that its audio capture API would let the apps decide if they allow to be captured 😕

rom1v avatar Feb 01 '21 06:02 rom1v

I'm confused. Some apps can record and stream screen to live broadcast platform like douyu or huya on android phone, and there are both video and audio in it. How can these apps do it?

MC-dusk avatar Feb 01 '21 07:02 MC-dusk

Some apps do not really capture audio output, they use the microphone (so if you talk or make noise next to the device, you can ear it).

rom1v avatar Feb 01 '21 08:02 rom1v

Some apps do not really capture audio output, they use the microphone

I think it does make sense. For example, I tried du-recorder and it worked just as you said. However, I'm using Huawei P30 with Android 10 (or called EMUI10), and there is a default screen record app in it which can record both video and audio. It can let you choose recording microphone or not which means the sound inside can be captured separately. I tried it and it worked, just sound inside from my app, no voice from outside. Is it because the app is a system app which has special authority, or the Android system is modified by Huawei?

MC-dusk avatar Feb 01 '21 09:02 MC-dusk

If you can dump the app, I'm interested.

adb shell pm list packages -f

Then adb pull the apk.

rom1v avatar Feb 01 '21 10:02 rom1v

Here is it. HwScreenRecorder.zip

MC-dusk avatar Feb 01 '21 11:02 MC-dusk

OK thank you, it seems that they added an internal AudioSource NEW_INTERFACE_REMOTE_SUBMIX having value 10007.

To test on your device, could you apply these changes, please?

diff --git a/app/src/main/java/com/rom1v/sndcpy/RecordService.java b/app/src/main/java/com/rom1v/sndcpy/RecordService.java
index 8486332..5bd740b 100644
--- a/app/src/main/java/com/rom1v/sndcpy/RecordService.java
+++ b/app/src/main/java/com/rom1v/sndcpy/RecordService.java
@@ -151,7 +151,7 @@ public class RecordService extends Service {
         AudioRecord.Builder builder = new AudioRecord.Builder();
         builder.setAudioFormat(createAudioFormat());
         builder.setBufferSizeInBytes(1024 * 1024);
-        builder.setAudioPlaybackCaptureConfig(createAudioPlaybackCaptureConfig(mediaProjection));
+        builder.setAudioSource(10007);
         return builder.build();
     }
 

rom1v avatar Feb 01 '21 11:02 rom1v

Well, it seems that the app sndcpy doesn't work if change the code

-        builder.setAudioPlaybackCaptureConfig(createAudioPlaybackCaptureConfig(mediaProjection));
+        builder.setAudioSource(10007);

VLC on PC doesn't receive any stream, the time keeps on 00:00.

MC-dusk avatar Feb 01 '21 13:02 MC-dusk

I believe the hidden NEW_INTERFACE_REMOTE_SUBMIX requires android.permission.CAPTURE_AUDIO_OUTPUT, which is only granted to non-third party applications and why the huawei app is capable of using it. Unless the system is rooted, using it in sndcpy will not be possible.

acceleration3 avatar Feb 12 '21 23:02 acceleration3

I also encountered this problem. At present, not all application audio support is captured, but these applications are unlikely to make changes to be captured, and it may require developers to spend some precious time on technical or For functional additions, you can check how this software implements audio forwarding for all applications, https://www.apowersoft.cn/phone-mirror, I am very envious of the developer’s wisdom and technology, and I hope this program can become better!

Zlylanyun avatar Jul 12 '21 07:07 Zlylanyun

To capture all audio, some programs typically use the microphone. But this is not a real solution, it also captures the environment.

rom1v avatar Jul 12 '21 07:07 rom1v

You are right, it is true in some programs, although this is not a real solution, but before we can figure out and find a more suitable solution, it is also very good to capture all the audio by capturing the environment. Yes, although it is not a very good real solution, it is better than nothing~ The specific content and decision still need to be carefully evaluated by the developer. I only considered the completeness of the function. Developers need to consider many aspects, you can check my suggestions, thank you!

Zlylanyun avatar Jul 12 '21 09:07 Zlylanyun

A better solution is just to use audio bluetooth separately.

Also see my comment here: https://www.reddit.com/r/Android/comments/o4pdxt/scrcpy_now_supports_android_12/h2ipu7y/?context=3

rom1v avatar Jul 12 '21 10:07 rom1v

I wonder if its possible to fake bluetooth over USB.

Zero3K avatar Jul 31 '21 15:07 Zero3K

A better solution is just to use audio bluetooth separately.

Also see my comment here: https://www.reddit.com/r/Android/comments/o4pdxt/scrcpy_now_supports_android_12/h2ipu7y/?context=3

Well, that works, but bluetooth can have bad quality, some PCs don't have bluetooth chips and having it work over ip is much more universally usable (longer distances, etc.).

Is there a way to allow to have a PC be a real android audio sink (like a bluetooth device) by something like dlna/upnp or something like that?

alexmo1997 avatar Jan 29 '22 15:01 alexmo1997

A better solution is just to use audio bluetooth separately.

Also see my comment here: https://www.reddit.com/r/Android/comments/o4pdxt/scrcpy_now_supports_android_12/h2ipu7y/?context=3

Apologies for reviving this old thread but how can I use audio bluetooth thing you mentioned? I am unable to recieve call audio on my PC through sndcpy. Is there any way to make my phone think that my PC is an audio device (like bluetooth earphones) so I can use bluetooth to recieve call audio on my PC?

cybr47 avatar Aug 28 '23 23:08 cybr47

A better solution is just to use audio bluetooth separately. Also see my comment here: https://www.reddit.com/r/Android/comments/o4pdxt/scrcpy_now_supports_android_12/h2ipu7y/?context=3

Apologies for reviving this old thread but how can I use audio bluetooth thing you mentioned? I am unable to recieve call audio on my PC through sndcpy. Is there any way to make my phone think that my PC is an audio device (like bluetooth earphones) so I can use bluetooth to recieve call audio on my PC?

As that said above, try UWP Bluetooth Audio Receiver

MC-dusk avatar Sep 04 '23 04:09 MC-dusk

A better solution is just to use audio bluetooth separately. Also see my comment here: https://www.reddit.com/r/Android/comments/o4pdxt/scrcpy_now_supports_android_12/h2ipu7y/?context=3

Apologies for reviving this old thread but how can I use audio bluetooth thing you mentioned? I am unable to recieve call audio on my PC through sndcpy. Is there any way to make my phone think that my PC is an audio device (like bluetooth earphones) so I can use bluetooth to recieve call audio on my PC?

As that said above, try UWP Bluetooth Audio Receiver

Unfortunately, it's unable to receive call audio.

cybr47 avatar Sep 04 '23 04:09 cybr47