检查 Android MediaRecorder 是否正在录制 [英] Check to see if Android MediaRecorder is Recording

查看:121
本文介绍了检查 Android MediaRecorder 是否正在录制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Android 2.2 编写了一些代码,使用 Android MediaPlayer 播放音频文件.没有深入代码的细节,我注意到存在一个名为

I've written some code for Android 2.2 that plays an audio file using the Android MediaPlayer. Without getting into the details of the code, I noticed that there exists a function called

isPlaying()

允许您检查 MediaPlayer 当前是否正在播放音频文件.因此,例如,当以下代码片段运行时

that allows you to check if an audio file is currently being played by the MediaPlayer. So, for example, when the following snippet of code runs

Toast.makeText(getApplicationContext(), "Sound playing is: " +
        mediaPlayer.isPlaying(), Toast.LENGTH_SHORT).show();

它显示以下消息

Sound playing is: true / false

取决于是否有声音播放.

depending on whether there's sound playing or not.

然而,当我编写一些代码来使用 Android MediaRecorder 录制来自麦克风的声音时,我注意到没有看起来像存在一个名为

When I wrote some code to record sound from the microphone using the Android MediaRecorder, however, I noticed that there did not look like there exists a function called

isRecording()

检查是否正在录制.

所以,我想知道程序员是否有责任通过在他们的代码中嵌入一些逻辑来确定录音是否正在进行 - 或者是否确实存在一种方法来做到这一点(检查录音是否在进行中)使用 Android API 提供的另一个内置函数.

So, I was wondering if the onus is on the programmer then to figure out if a recording is in progress by embedding some logic into their code - or if perhaps there indeed exists a way to do this (check if a recording is in progress) by using another in-built function offered by the Android API.

推荐答案

终究没有这样的功能.我认为尝试在代码中嵌入一些逻辑以干净利落地做到这一点是有意义的.

Doesn't look like there is such a function after all. I think it makes sense to try to embed some logic in the code to do this cleanly.

这篇关于检查 Android MediaRecorder 是否正在录制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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