stop called in an invalid state: 1 - android

I am trying to build a call recorder in android. I am using the MediaRecorder Class:
When My App reaches the following line: recorder.stop() I get the following error:
stop called in an invalid state: 1
What causes that problem?
Thanks in advance,
kobi

From the MediaRecorder documents page:
http://developer.android.com/reference/android/media/MediaRecorder.html
Looking at the state diagram given, you can only call stop() when the MediaRecorder is in the state Recording
Hard to tell what you are doing wrong without code, but you have to be in the wrong state to call stop().

Related

Android MediaPlayer Error (-2,0)

Anyone familiar with this error with Android MediaPlayer ?
MediaPlayer: Error (-2,0)
It's not documented.
It probably comes from OpenCore, which MediaPlayer is a high level abstraction of. "-2" means that some operation was canceled.
Here the list of error codes.
/*
Error due to cancellation
*/
const PVMFStatus PVMFErrCancelled = (-2);
Here is the doc with the detailed code description.
3.8. PVMFErrCancelled
This error code is returned when some old request is cancelled. In that sense this error is actually
an expected value and should not be treated as a fatal error.
So, you may probably ignore it, or double check how you implemented the workflow and whether it fits the expected one (you can find it in MediaPlayer class' reference).
From MediaErrors.h, include/utils/Errors.h, and unix_system_errors we can see that MediaPlayer error code -2 can mean:
Signal from CodecBase to MediaCodec that the component was not found.

Deezer sdk android : seek with the TrackPlayer class

I initialized my TrackPlayer like this :
trackPlayer = new TrackPlayer((Application) context.getApplicationContext(), deezerConnect, new WifiAndMobileNetworkStateChecker());
trackPlayer.playTrack(trackId);
Then, I want to seek into the track with this code :
if (trackPlayer != null && trackPlayer.isAllowedToSeek()) {
trackPlayer.seek(newPositionInMs);
}
I get this error :
java.lang.IllegalStateException: Unable to retrieve AudioTrack pointer for getSampleRate()
at android.media.AudioTrack.native_get_playback_rate(Native Method)
If everyone can help me,
Thanks
This issue might happen if you try to seek too soon. When you call playTrack(), the player needs to fetch the requested track information, and download the track, which means that the player might not be initialised yet when you call the seek method.
You might want to wait for the player to be in the READY or PLAYING state before seeking.
To do so, just add a PlayerStateChangedListener on your player.

[Android source code learning ]How does IMediaRecorder.cpp do the Muxer job?

I want to extract the media muxer part from the MediaRecorder.java.
I've been reading the android source code, the version is Jellybean(4.2.2). The corresponding is android_media_MediaRecorder.cpp andMediaRecoder.cpp, however, there is no clear definition of media muxer process in the start() function.
So I read the IMediaRecorder.cpp , but there is still no clear definition:
status_t start()
{
ALOGV("start");
Parcel data, reply;
data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
remote()->transact(START, data, &reply);
return reply.readInt32();
}
I don't know what to look at now... Does anyone know about this??
Thanks for any advice!
OK, I found some useful article.
Class MPEG4Writer is doing this job, and you can find a MPEG4Writer.cpp in the source code.

Android MediaPlayer Error (-38,0)

I got a problem with my media player. Sometimes an error occurs and the on error is called. There I have the Mediaplayer and two int as parameters.
The first int is "-38" and the second one is "0".
What does that mean?
EDIT: Code: http://pastebin.com/3XBaFYwF
Here's my logcat #Blundell LogCat:
http://pastebin.com/Wbjm3QCW
error 38 means you are asking the MediaPlayer to do something when in the wrong state. You won't be able to fathom your error just from this.
Look at your Logcat before and after this error code and see what else has gone wrong. It's more than like you are calling start before the MediaPlayer has prepared or some other error of state.
see http://developer.android.com/reference/android/media/MediaPlayer.html#StateDiagram

Regarding IllegalStateExceptions, MediaPlayer, failed prepares and State codes

I have been struggling quite a lot with our beloved MediaPlayer class...
Specifically I want to simply play sounds from some Files...
I am getting two specific types of errors actually, and not continuesly but it seems like random... Sometimes 10 files are played rigth away with no errors, then the MediPlayer seems to stop accepting another File...
Ok the first error :
- 05-26 15:02:00.916: ERROR/MediaPlayer(25793): error (1, -4)
- 05-26 15:02:00.916: ERROR/setupplayer(25793): java.io.IOException: Prepare failed.: status=0x1
Well for this one I have seen several solutions :
use
mp.setDataSource(ins.getFD()); (with ins being an inputstream to my File)
and/or to use
mp.setDataSource(ins.getFD(), 0, f.length());
Both unfortunately won't solve the problem, and I would simply LOVE to know what the very exhaustive error(1,-4) is... And where can I find the codes of the States of the MediaPlayer ?
Also I have tried using prepareAsync() instead of prepare() but to be honest it doesn't seem to make any difference at all..
The second error is the Exception which is thrown :
05-26 15:17:30.456: ERROR/playNextPlayer(27303): Error caught : java.lang.IllegalStateException
Which, I guess, might be related to the first error/problem ?
Try mp.setDataSource(String path)
For example,mp.setDataSource("sdcard/1.mp3");
The error is coming because of incorrect path or FileDescriptor.
You should check the State Diagram of Mediaplayer class

Categories

Resources