麦克风状态

发布于 2024-12-11 03:39:18 字数 149 浏览 4 评论 0原文

我正在编写一个使用 MediaRecorder 来录制音频的应用程序。 (我使用Android 2.1)

  1. 在开始录音之前我想知道麦克风的状态(忙还是闲)?
  2. 如果麦克风繁忙,我可以获得独占访问权吗?

提前致谢!

I am writing an application that uses MediaRecorder for recording audio. ( I use Android 2.1 )

  1. Before start recording I want to know the microphone's state (is it busy or no)?
  2. If the microphone busy, can I get exclusive access to it?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽清梦 2024-12-18 03:39:19

回答1个问题:
读了很多文章后我意识到这是不可能的。

Answer to 1 question:
After reading many articles I realized that it was impossible.

晌融 2024-12-18 03:39:19

这是一个老问题,但我展示了解决这个问题的方法。也许有人需要这种帮助。注意:这是一种肮脏的方式,但对我有用。

您可以尝试/捕获 MediaRecorderObject.start()。如果麦克风正忙,您将收到异常

MediaRecorder myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);

try {
        myAudioRecorder.prepare();
        myAudioRecorder.start();

    }
    catch (Exception exception) {
        Toast.makeText(getApplicationContext(), "Mic in use", Toast.LENGTH_LONG).show();

    }

It's an old question but I show the way I solve this problem. Maybe someone will need this help. Note: it's a dirty way but it worked for me.

You can try/catch MediaRecorderObject.start(). You will get an exception if the mic is busy

MediaRecorder myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);

try {
        myAudioRecorder.prepare();
        myAudioRecorder.start();

    }
    catch (Exception exception) {
        Toast.makeText(getApplicationContext(), "Mic in use", Toast.LENGTH_LONG).show();

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文