尝试捕捉异常,因为当您尝试使用麦克风时可能会遇到异常,您可以处理它。
是否正在使用麦克风“的麦克风实际上将准备精美即使麦克风正在使用中”
OR 此代码段可能会给你一个想法
//returns whether the microphone is available
public static boolean getMicrophoneAvailable(Context context) {
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(new File(context.getCacheDir(), "MediaUtil#micAvailTestFile").getAbsolutePath());
boolean available = true;
try {
recorder.prepare();
recorder.start();
}
catch (Exception exception) {
available = false;
}
recorder.release();
return available;
}
最后
以上就是朴素黑猫最近收集整理的关于android 副mic测试,如何检查android麦克风是否可用?的全部内容,更多相关android内容请搜索靠谱客的其他文章。
发表评论 取消回复