大佬教程收集整理的这篇文章主要介绍了java – 如何拦截Android设备上的音频流?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
任何建议是赞赏,它可以是Java或C解决方案.
public class AudioRecorder { final MediaRecorder recorder = new MediaRecorder(); final String path; /** * Creates a new audio recording at the given path (relative to root of SD * card). */ public AudioRecorder(String path) { this.path = sanitizePath(path); } private String sanitizePath(String path) { if (!path.startsWith("/")) { path = "/" + path; } if (!path.contains(".")) { path += ".3gp"; } return Environment.getExternalStorageDirectory().getAbsolutePath() + path; } /** * Starts a new recording. */ public void start() throws IOException { String state = android.os.Environment.getExternalStorageState(); if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) { throw new IOException("SD Card is not mounted. it is " + state + "."); } // make sure the directory we plan to store the recording in exists File directory = new File(path).getParentFile(); if (!directory.exists() && !directory.mkdirs()) { throw new IOException("Path to file Could not be created."); } recorder.setAudiosource(MediaRecorder.Audiosource.MIC); recorder.setOutputFormat(MediaRecorder.outputFormat.THREE_GPp); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); recorder.start(); } /** * Stops a recording that has been prevIoUsly started. */ public void stop() throws IOException { recorder.stop(); recorder.release(); } }
以上是大佬教程为你收集整理的java – 如何拦截Android设备上的音频流?全部内容,希望文章能够帮你解决java – 如何拦截Android设备上的音频流?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。