rom1v / sndcpy

Android audio forwarding (scrcpy, but for audio)
MIT License
3.25k stars 297 forks source link

How to capture audio from restricted apps? #113

Open MC-dusk opened 3 years ago

MC-dusk commented 3 years ago

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?

rom1v commented 3 years ago

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

MC-dusk commented 3 years ago

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?

rom1v commented 3 years ago

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).

MC-dusk commented 3 years ago

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?

rom1v commented 3 years ago

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

adb shell pm list packages -f

Then adb pull the apk.

MC-dusk commented 3 years ago

Here is it. HwScreenRecorder.zip

rom1v commented 3 years ago

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();
     }
MC-dusk commented 3 years ago

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.

acceleration3 commented 3 years ago

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.

Zlylanyun commented 3 years ago

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!

rom1v commented 3 years ago

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

Zlylanyun commented 3 years ago

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!

rom1v commented 3 years ago

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

Zero3K commented 3 years ago

I wonder if its possible to fake bluetooth over USB.

alexmo1997 commented 2 years ago

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?

cybr47 commented 1 year ago

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?

MC-dusk commented 1 year ago

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

cybr47 commented 1 year ago

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.