mediaPlayer prepare nullpointer exception - android

it's realy rare error for me but.. It's error. Can't understand why.
error just on line
mp.prepare();
from logcat :
Caused by: java.lang.NullPointerException
at myapp.activity.com.myApp.media(myApp.java:281)
at myapp.activity.com.myApp$showLogotype.doInBackground(myApp.java:397)
at myapp.activity.com.myApp$showLogotype.doInBackground(myApp.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305
Someone can explain me :( ?
Im using asynctask for prepare and load all datas and showing logo while my app reading datas and preparing for mediaPlayer( in logcat : mediaPlayer.prepare() getting 5-10 seconds) )
But im sometimes have this realy rare error for me(cos i can't understand how to get this error and he is realy rare for me)
Please explain me if anyone know :( or please< tell me how to fix this :(
code of function :
public void media() throws IllegalArgumentException, IllegalStateException, IOException
{
mp = new MediaPlayer();
mp.setDataSource(stream);
mp.prepare();
}
Regards,Peter. Sorry for my bad english, hope u understand me

A null pointer exception happens when you try to access a variable or object that is not properly assigned/instantiated. My guess is that you either have not assigned the media player, or have not given the player the data you want to prepare. Resource: http://developer.android.com/reference/android/media/MediaPlayer.html

Can't catch this problem. I manualy catch and solve for some problem. I think media player have a bug .. .and this problem not fixing.

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.

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.

VideoView / MediaPlayer Error (1, -18)

I have an application that is built to API level 2.2. This application contains a video that starts playing as soon as it is launched. The video is played inside a VideoView and the actually video file is stored in my internal storage (files directory for my apps package).
Most of the time it starts up just fine. But occasionally I get an error pop - up that says "Sorry, this video cannot be played." and has an Ok button. As soon as I press the ok button the video starts playing correctly. I need to figure out what is causing this error, or at the very least how I can catch whatever error it is and have it try again since it always works perfect after I hit ok. Inside the logs when this error box is shown I see these messages:
ERROR/PVOMXAudDecNode(21215): Ln 2232 OMX_EventError nData1 -2147479547 nData2 0
ERROR/PlayerDriver(21215): Command PLAYER_PREPARE completed with an error or info -18
ERROR/MediaPlayer(9282): message received msg=100, ext1=1, ext2=-18
ERROR/MediaPlayer(9282): error (1, -18)
ERROR/MediaPlayer(9282): callback application
ERROR/MediaPlayer(9282): back from callback
ERROR/MediaPlayer(9282): Error (1,-18)
DEBUG/VideoView(9282): Error: 1,-18
Where can I find a reference as to what exactly error code -18 indicates? And does anyone have any suggestions I could try to prevent it from happening in the first place. I have only observed This error on the Sprint Epic 4g.
Edit: well as far as I can tell no exceptions are getting thrown to me. I assume what is happening is that the video view knows to catch whatever exception is causing and it throws up the pop-up. Inside my log there is no exception stack trace just this reference to error -18.
As for how I am calling prepare. I use this:
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer arg0) {
mVideoView.start();
}
});
and this:
mVideoView.setVideoPath(file.getAbsolutePath());
it calls prepare as part of setVideoPath (I assume it does anyway, but this method is undocumented). which causes onPrepared to get called in my listener.
Edit 2: for now i've just added an onErrorListener like so:
EDIT IMORTANT! this code will infinte error loop on ICS. For ICS devices I took out the setPath call, and returned false instead. It tries again by itself once and it succeeds.
mVideoView.setOnErrorListener(new OnErrorListener(){
#Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
Log.i(myTag, "MP ERROR: "+ arg1 + " - " + arg2);
mVideoView.setVideoPath(file.getAbsolutePath());
return true;
}
});
this catches the error and I can see in my logs that arg2 = -18 when this error happens. I just have it retry and return true so it doesn't throw up the dialog. So far i've never seen it fail twice in a row so this always starts the video correctly and doesn't make infinite loop.
I am still very interested if anyone can tell me exactly what error code -18 indicates though.
How do you catch potential exceptions thrown by prepare()? Do you catch IOException specifically and then retry calling the prepare()?
Try using prepareAsync() instead, which does not block and calls listener when player is ready. Also it does not throw IOException.
If you are running it on Froyo or Gingerbread the problem might be your device is not supporting playback of the file. Lower versions do not support videos encoded with formats other than baseline format. You may use some tools like video info on pc and check if the files are baseline formatted.

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