FileOutStream无法创建文件
private void runRecord(){ getGlobalTaskDispatcher(TaskPriority.DEFAULT).asyncDispatch(() -> { if(audioCapturer == null) { initRecord(); } File file = new File(getFilesDir() + File.separator + "record.pcm"); //file = new File("/Sounds" + File.separator + "SoundRecorder" + File.separator + "record.pcm"); //file = new File("/Soundss" + File.separator + "record.pcm"); try (FileOutputStream outputStream = new FileOutputStream(file)) { byte[] bytes = new byte[BUFFER_SIZE]; audioCapturer.start(); while (isRecording && audioCapturer.read(bytes, 0, bytes.length) != -1) { outputStream.write(bytes); bytes = new byte[BUFFER_SIZE]; outputStream.flush(); } outputStream.close(); //stop record if (audioCapturer.stop()) { Date dNow = new Date(); SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd_HHmmss"); String filename = sdf.format(dNow); String wavPath = getFilesDir() + File.separator + filename + ".wav"; //String wavPath = "/Sounds" + File.separator + "SoundRecorder" + File.separator + filename + ".wav"; //String wavPath = "/Soundss" + File.separator + filename + ".wav"; ShellUtils.tranPcmToWavFile(file, wavPath); HiLogUtils.info("MainAbilitySlice", "wavPath:" + wavPath); } audioCapturer.release(); } catch (IOException exception) { HiLogUtils.error(TAG, "record exception," + exception.getMessage()); } }); }运行后,没有出发exception,但是也没有文件产生。申请了media read和media write权限。
5
2
8
浏览265 发布于2021-12-21 12:01未知归属地
全部评论
最多点赞
最新发布
最早发布
写回答
所见即所得编辑器, editor1
工具栏
0/50000
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要发帖子
了解社区公约,与您携手共创和谐专业的开发者社区。









































苏公安网备 32011402010933号