如何在Android设备上录制内部音频或录制MediaPlayer音频流? [英] How to record internal audio on Android devices or record MediaPlayer Audio Stream?

查看:821
本文介绍了如何在Android设备上录制内部音频或录制MediaPlayer音频流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试录制在MediaPlayer中播放的音频流.

I'm currently trying to record an audio stream which is played in MediaPlayer.

实际上,我发现了一些博客文章,说由于安全/版权原因,这是不可能的,但是我找不到来自Android/Google文档的任何官方声明.此外,还有诸如Mobizen之类的屏幕捕获应用程序,可以录制内部音频(至少可以使用三星设备).

Actually I found some blog-post, saying it's not possible because of security / copyright reasons, but I couldn't find any official statements from Android/Google docs. Furthermore, there are screen capture apps like Mobizen which can record internal audio (at least Samsung devices seems to work).

有人可以告诉我是否,

  1. 官方不允许/不支持内部音频吗?
  2. 是否可以用AudioRecorder录制在MediaPlayer中播放的流?
  1. internal audio is officially not allowed / supported?
  2. it's possible to record a stream with AudioRecorder which is played in MediaPlayer?

我不确定现在是否要进入黑暗的一面?

I'm not so sure if I'm entering the dark side at the moment?

我已经尝试回答的第二个问题:

What I already tried to answer the 2nd question:

  • 录制了不同的MediaRecorder.AudioSource,但全部录制了麦克风
  • 找到逐字节查看录音,但这不适用于MediaPlayer
  • recorded different MediaRecorder.AudioSource, but all record the microphone
  • found byte by byte for recording, but this is not working with MediaPlayer

推荐答案

随着新的Android 10 API的出现,终于有了AudioPlaybackCapture API.

Coming with the new Android 10 API, there finally is an AudioPlaybackCapture API.

此API使应用程序能够复制其他应用程序正在播放的音频.此功能类似于屏幕捕获,但适用于音频.

This API gives apps the ability to copy the audio being played by other apps. This feature is the analog of screen capture, but for audio.

我个人还没有测试过,但是根据开发指南,这是捕获音频的必要步骤.

I personally haven't tested it, yet, but here are the required steps to capture audio, based on the dev guide.

捕获音频所需的权限:

应用必须显示显示的提示MediaProjectionManager.createScreenCaptureIntent() ,并且用户必须批准.

The app must bring up the prompt displayed by MediaProjectionManager.createScreenCaptureIntent(), and the user must approve it.

捕获和播放应用必须位于相同的用户个人资料中.

The capturing and playing apps must be in the same user profile.

要捕获音频,则需要构建 AudioRecord 对象,然后向其中添加 AudioPlaybackCaptureConfiguration :

To capture the audio, you then need to build an AudioRecord object and add the AudioPlaybackCaptureConfiguration to it:

  1. 致电 AudioPlaybackCaptureConfiguration.Builder.build() 来构建 AudioPlaybackCaptureConfiguration .

通过调用AudioRecord "noreferrer"> setAudioPlaybackCaptureConfig .

Pass the configuration to the AudioRecord by calling setAudioPlaybackCaptureConfig.

您还可以通过AUDIO_USAGEUID约束捕获,请参见:限制音频内容的捕获

You can also constrain the capture by AUDIO_USAGE or a UID, see: Constraining capture by audio content

我强烈建议您查看 Android开发指南.

限制

运行Android 10的设备很少.谷歌尚未发布其市场份额,但我们可以猜到它最多不到10%,这是Android 9.0的市场份额.

Very few devices are running on Android, 10. Google has not released yet the market share, but we can guess that it is at most less than 10%, which is the market share of Android 9.0.

在截至2019年5月7日的7天内收集的数据.未显示分布低于0.1%的任何版本.来源:分发控制台

这篇关于如何在Android设备上录制内部音频或录制MediaPlayer音频流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆