Invalid State Of Audio Recorder (Bad FilePath?)
up vote
0
down vote
favorite
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.
java android-studio
add a comment |
up vote
0
down vote
favorite
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.
java android-studio
Why are you catching the error from recorder.prepare() and just printing it and going ahead with recorder.start() ? If prepare() throws a exception, then the Media recorder is in a invalid state. Can you see what kind of exception in thrown my prepare? if it does, please post the stacktrace. Also make sure you have requested and received permission to write to external storage.
– Abhijith Shivaswamy
Nov 11 at 6:33
So I did the recorder.start() like that because thats how it is done in the documentation, so I was trying to be like that. I found the stack error - and posted it. Thank you for guiding me!
– Gorgochef
Nov 11 at 6:52
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
java android-studio
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.
java android-studio
java android-studio
edited Nov 11 at 6:51
asked Nov 11 at 5:48
Gorgochef
305
305
Why are you catching the error from recorder.prepare() and just printing it and going ahead with recorder.start() ? If prepare() throws a exception, then the Media recorder is in a invalid state. Can you see what kind of exception in thrown my prepare? if it does, please post the stacktrace. Also make sure you have requested and received permission to write to external storage.
– Abhijith Shivaswamy
Nov 11 at 6:33
So I did the recorder.start() like that because thats how it is done in the documentation, so I was trying to be like that. I found the stack error - and posted it. Thank you for guiding me!
– Gorgochef
Nov 11 at 6:52
add a comment |
Why are you catching the error from recorder.prepare() and just printing it and going ahead with recorder.start() ? If prepare() throws a exception, then the Media recorder is in a invalid state. Can you see what kind of exception in thrown my prepare? if it does, please post the stacktrace. Also make sure you have requested and received permission to write to external storage.
– Abhijith Shivaswamy
Nov 11 at 6:33
So I did the recorder.start() like that because thats how it is done in the documentation, so I was trying to be like that. I found the stack error - and posted it. Thank you for guiding me!
– Gorgochef
Nov 11 at 6:52
Why are you catching the error from recorder.prepare() and just printing it and going ahead with recorder.start() ? If prepare() throws a exception, then the Media recorder is in a invalid state. Can you see what kind of exception in thrown my prepare? if it does, please post the stacktrace. Also make sure you have requested and received permission to write to external storage.
– Abhijith Shivaswamy
Nov 11 at 6:33
Why are you catching the error from recorder.prepare() and just printing it and going ahead with recorder.start() ? If prepare() throws a exception, then the Media recorder is in a invalid state. Can you see what kind of exception in thrown my prepare? if it does, please post the stacktrace. Also make sure you have requested and received permission to write to external storage.
– Abhijith Shivaswamy
Nov 11 at 6:33
So I did the recorder.start() like that because thats how it is done in the documentation, so I was trying to be like that. I found the stack error - and posted it. Thank you for guiding me!
– Gorgochef
Nov 11 at 6:52
So I did the recorder.start() like that because thats how it is done in the documentation, so I was trying to be like that. I found the stack error - and posted it. Thank you for guiding me!
– Gorgochef
Nov 11 at 6:52
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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();
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
1
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
1
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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();
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
1
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
1
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
add a comment |
up vote
1
down vote
accepted
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();
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
1
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
1
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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();
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();
answered Nov 11 at 6:56
Abhijith Shivaswamy
3115
3115
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
1
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
1
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
add a comment |
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
1
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
1
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
So I used: File file = new File(this.getFilesDir(), "Test"); recorder.setOutputFile(file); However this says that I need an API of 26 to use this method. Is there a work around for this for an API like 21?
– Gorgochef
Nov 11 at 7:31
1
1
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
on which method are you getting this message?
– Abhijith Shivaswamy
Nov 11 at 7:32
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
recorder.setOutputFile(file); Specifically. It seems like it just wants me to pass a string name into it
– Gorgochef
Nov 11 at 7:34
1
1
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
You'll need to either use setOutputFile(String path) or setOutputFile(FileDescriptor), you can use setOutputFile(file.getAbsolutePath())
– Abhijith Shivaswamy
Nov 11 at 7:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246190%2finvalid-state-of-audio-recorder-bad-filepath%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why are you catching the error from recorder.prepare() and just printing it and going ahead with recorder.start() ? If prepare() throws a exception, then the Media recorder is in a invalid state. Can you see what kind of exception in thrown my prepare? if it does, please post the stacktrace. Also make sure you have requested and received permission to write to external storage.
– Abhijith Shivaswamy
Nov 11 at 6:33
So I did the recorder.start() like that because thats how it is done in the documentation, so I was trying to be like that. I found the stack error - and posted it. Thank you for guiding me!
– Gorgochef
Nov 11 at 6:52