Android MediaPlayer Error (-2,0) - android

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.

Related

MediaControllerCompat - java.lang.IllegalArgumentException: Bad direction 3

I'm issuing a simple command to my mediaControllerCompat:
controller.adjustVolume(-1, 0);
Yet my app FCs with...
java.lang.IllegalArgumentException: Bad direction 3
at android.os.Parcel.readException(Parcel.java:1469)
at android.os.Parcel.readException(Parcel.java:1419)
at android.media.IAudioService$Stub$Proxy.adjustStreamVolume(IAudioService.java:1097)
at android.media.AudioManager.adjustStreamVolume(AudioManager.java:952)
at android.support.v4.media.session.MediaSessionCompat$MediaSessionImplBase.adjustVolume(MediaSessionCompat.java:1376)
at android.support.v4.media.session.MediaSessionCompat$MediaSessionImplBase.access$1700(MediaSessionCompat.java:963)
at android.support.v4.media.session.MediaSessionCompat$MediaSessionImplBase$MediaSessionStub.adjustVolume(MediaSessionCompat.java:1602)
at android.support.v4.media.session.MediaControllerCompat$MediaControllerImplBase.adjustVolume(MediaControllerCompat.java:969)
at android.support.v4.media.session.MediaControllerCompat.adjustVolume(MediaControllerCompat.java:252)
at pl.qus.xenoamp.NewMainActivity.onKeyDown(NewMainActivity.java:1149)
MainActivity being the caller of mentioned line... What is WRONG?!
This was an internal bug in the Android Support Library has been fixed as of version 23.1.0.
Previous Answer
This is a bug in the support library that affects pre-API 21 devices that use local playback (i.e., have not called setPlaybackToRemote()) - the order of parameters sent to AudioManager.adjustStreamVolume() as per the source code is incorrect - hence why the direction appearing as 3 - the value for STREAM_MUSIC.
You may be able to temporarily work around it by always calling setPlaybackToRemote() on pre-API 21 devices, passing in a VolumeProviderCompat that does correctly call AudioManager.adjustStreamVolume(), but you must also handle the other methods of VolumeProviderCompat such as retrieving the max volume (via getStreamMaxVolume()) and current volume (via getStreamVolume()) as well as setting the volume (via setStreamVolume()).
I came across the same error using API 23 (not the Support Library) and running on an M device. I solved it by listening for the error and calling an API 1 method in its place, when necessary.
try {
...
} catch (IllegalArgumentException e) {
audioManager.setStreamVolume(STREAM, VOLUME, FLAGS);
}
Since the Compat interface calls the internal methods for system volume control, you could also instantiate an instance AudioManager if you are not directly declaring one already.

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

Unclear error when playing a video in a VideoView

I'm trying to play a video (by a uri) in a VideoView and sometimes get the following errors:
E/MediaPlayer(15861): error (1, -2147483648)
D/MediaPlayer(15861): Couldn't open file on client side, trying server side
W/MediaPlayer(15861): mediaplayer went away with unhandled events
I found that the "list" of codes can be found in the following source code:
https://github.com/android/platform_external_opencore/blob/master/pvmi/pvmf/include/pvmf_return_codes.h
(thanks to the thread Complete list of MediaPlayer error codes)
But that does not make things more clear, there's nothing there about -2147483648, and the 1 I get is positive and in this source it says that error codes are negative.
Same thing was reported in this thread: Playing youtube video in a videoview, though he did not ask about what this error means (nor did he get any helping answer).
Anyone has an idea of the meaning of this error?
Thanks.
Edit
I'm trying to show youtube videos, the url of the stream is taken from http://www.youtube.com/get_video_info?&video_id=VIDEO_ID and it's being done asynchronously.
When the result gets back, this is the code I'm using:
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
setVideoURI(videoStream);
}
});
This is being executed by a class which extends VideoView.
1 stand for MEDIA_ERROR_UNKNOWN. and -2147483648 is a myth
Refer to the documentation for further details.
This kind of error occurs when trying to play an invalid url. Assuming you are not using third party libraries.

stop called in an invalid state: 1

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().

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