gpt4 book ai didi

android - 打开失败 :EROFS read only file system android

转载 作者:行者123 更新时间:2023-11-29 17:50:34 34 4
gpt4 key购买 nike

我正在尝试播放声音并通过手机的麦克风录制,然后将其写入文件(3gp 格式)。
我出于某些测试目的使用了线程。问题是我收到类似

的错误
> caused by libcore.io.ErrnoException: open failed: EROFS (read only file system)

虽然我没有尝试访问任何系统文件。我环顾四周,发现 this :

我添加了写/读权限,但仍然不起作用。

这是生成错误的代码:

public void startRecording(){

MediaRecorder mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"xfile.3gp");
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
mRecorder.start();
} catch (Exception e) {
e.printStackTrace();
}
}

和线程 block :

super.onCreate(savedInstanceState);  
setContentView(R.layout.activity_main);

Thread thread=new Thread(new Runnable()
{
public void run()
{
try
{
genTone();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.post(new Runnable()
{
public void run()
{
playSound();
} });
}
});
thread.start();

播放声音的方法

void playSound(){
AudioTrack audioTrack= null;
try{
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length, AudioTrack.MODE_STATIC);
audioTrack.write(generatedSnd, 0, generatedSnd.length);

audioTrack.play();
Thread thr=new Thread(new Runnable(){
public void run(){
startRecording();
}
});
thr.start();

}
catch(Exception e)
{
System.out.print(e);
}
}

最佳答案

尝试

Environment.getExternalStorageDirectory().getAbsolutePath()+"/xfile.3gp"

代替

Environment.getExternalStorageDirectory().getAbsolutePath()+"xfile.3gp"

请注意,您的版本最终可能是

/sdcardxfile.3gp

而不是

/sdcard/xfile.3gp

因此出现只读文件系统错误

关于android - 打开失败 :EROFS read only file system android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23135152/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com