Reputation: 89
I have a recorder I'm trying to make to test it out and see how it works. However when I run it I get the error:
E/MediaRecorder: start called in an invalid state: 4
So I did some googlejitzu and figured out that my file path is wrong. This is my code:
final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("Test");
System.out.println("Hello");
try {
recorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
CountDownTimer countDownTimer = new CountDownTimer(30000, 1000) {
@Override
public void onTick(long l) {
}
@Override
public void onFinish() {
recorder.stop();
}
}.start();
So I guess I was wondering how to make a file path directory on the phone for the audio to be saved to.
The Error is:
11-11 01:49:48.275 23703-23703/com.example.arege.dayatalisten W/System.err: java.io.FileNotFoundException: Test: open failed: EROFS (Read-only file system)
11-11 01:49:48.276 23703-23703/com.example.arege.dayatalisten W/System.err: at libcore.io.IoBridge.open(IoBridge.java:455)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:128)
at android.media.MediaRecorder.prepare(MediaRecorder.java:834)
at com.example.arege.dayatalisten.ListeningToTheWorld.onStartCommand(ListeningToTheWorld.java:47)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3432)
at android.app.ActivityThread.-wrap21(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1633)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6316)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
11-11 01:49:48.277 23703-23703/com.example.arege.dayatalisten W/System.err: at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:187)
at libcore.io.IoBridge.open(IoBridge.java:441)
... 13 more
I have both required permissions.
Upvotes: 0
Views: 66
Reputation: 398
You are trying to write to a internal storage to which your app does not have access. It's not a rooted device.
You need to write your file to the External storage.
Use either: getFilesDir() or getExternalFilesDir()
(on Context or Activity) to get the directory and write the file to that location.
Psuedocode:
File file = new File(context.getFilesDir(), "Test");
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write("contents".getBytes());
outputStream.close();
Upvotes: 1