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.
Related
I'm running through a slideshow in an infinite loop. Every 'x' amount of time, I switch the video playing. First I stop the video, and then I load the new video. My app is crashing when I set the video path, with an error that there is an illegal state. It only happens once every couple thousand uses, so I cannot replicate it. That is, if I leave the app open for 24 hours on 100 devices, it will happen once per day on one device.
runOnUiThread() {
if (mVideoView!!.isPlaying) {
mVideoView!!.stopPlayback()
}
mVideoView!!.setVideoPath(filePath)
mVideoView!!.setOnErrorListener { mp, what, extra ->
LOG.e("Media player error: $what extra: $extra")
// Something's wrong, try again
slideshowHandler.removeCallbacksAndMessages(null)
slideshowHandler.postDelayed(slideshowRunner, 0)
true
}
if (startTime > 0) {
mVideoView!!.seekTo(startTime)
}
mVideoView!!.start()
}
}
java.lang.IllegalStateException
at android.media.MediaPlayer.prepareAsync(Native Method)
at android.widget.VideoView.openVideo(VideoView.java:356)
at android.widget.VideoView.setVideoURI(VideoView.java:265)
at android.widget.VideoView.setVideoURI(VideoView.java:248)
at android.widget.VideoView.setVideoPath(VideoView.java:239)
Any thoughts on what this could be? What state is invalid? Am I doing things in the wrong order?
I can't find any similar issues on SO. The app is running lollipop 5.1 (has to).
Edit: I'm fixing this right now using a try/catch. Seems like there is some underlying bug in Android that is causing this.
I have searched too much here on stack overflow but I am unable to find any solution of my problem.
I am getting a Media Player Error named 'MEDIA_ERROR_IO' code -1004.
I am stream an audio from server everything works good. song prepared and then starts in onPrepared() method.
Now the problem comes when there is an incoming call and phone starts ringing, and I pauses the song by calling mediaPlayer.pause() from my BroadcastReceiver class.
when the Phone call ends start the audio again by calling mediaPlayer.start()
the audio starts but after 2-3 seconds it stops with an Error that is MediaPlayer error (1, -1004).
Now What should I do?
Any Help is appreciable.
Thank you.
the audio starts but after 2-3 seconds it stops with an Error that is
MediaPlayer error (1, -1004).
First, Lets understand what error (1, -1004) means. -1004 is the error code for IO error. Below reference from MediaPlayer.java source code.
/** File or network related operation errors. */
public static final int MEDIA_ERROR_IO = -1004;
This type of error comes if for some reason, the media player is not able to connect to the server due to network issues. It could be bad internet connectivity at that instance or some network related reason due which the media player was unable to connect to the server. There are some other similar error codes that the media player can throw like time-outs or server died:
/** Some operation takes too long to complete, usually more than 3-5 seconds. */
public static final int MEDIA_ERROR_TIMED_OUT = -110;
/** Media server died.*/
public static final int MEDIA_ERROR_SERVER_DIED = 100;
Now What should I do?
To handle errors generated by media player at run time, you should implement Error Listener. You can handle the error in which ever way as you like for example restart the player.
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
switch(extra){
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
// Do Something
// eg. reset the media player and restart
break;
case MediaPlayer.MEDIA_ERROR_IO:
// Do Something
// eg. Show dialog to user indicating bad connectivity
// or attempt to restart the player
break;
case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
//Do Something
//eg. Show dialog that there was error in connecting to the server
// or attempt some retries
break;
}
//You must always return true if you want the error listener to work
return true;
}
});
I'm trying to play music from a ListView (which takes data from a file path). But everytime i click, it gets an error like this:
09-14 09:58:42.996 1229-1276/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
Even I use file path directly, it still doesn't work.
Here is my code:
private MediaPlayer mMediaPlayer;
private File dir = new File(Environment.getExternalStorageDirectory() + "/MyOwnMusicFolder");
private File[] files;
public void playSong(int position){ //position of the item in the ListView
if(mMediaPlayer !=null) {
if(mMediaPlayer.isPlaying()){
mMediaPlayer.pause();
}
try {
mMediaPlayer.setDataSource(dir + File.separator + files[position].getName());
mMediaPlayer.prepare();
mMediaPlayer.start();
}
catch (IOException e){
//something...
}
}
}
Edit: I'm using Android Studio + Android Studio Emulator
Edit 2: my mp3 files are completely normal
"Most likely, the tap sound got a AUDIO_OUTPUT_FLAG_FAST in order to use low-latency playback if possible, but the AudioTrack class considered the track settings to be incompatible with the low-latency audio output, so the flag got removed and the track got treated as if the flag hadn't been set to begin with. So I wouldn't consider this to be something to worry about.
As for the reason why the flag got denied; I'd still say that the most probable reason is a sample rate mismatch. The log in the question you linked to appears to have been added in this commit to the AOSP. But if we look at the master branch of the code base used on many Qualcomm-based devices we see that it still has the "AUDIO_OUTPUT_FLAG_FAST denied by client" log in the case were there was a sample rate mismatch. Which logs you get depends on the exact implemetation running on your device (i.e. which device and Android version you're running)."
Answer was taken from here. Credits to Michael
This most like is caused by mismatch on the sample rate and it should not affect the program runtime IF it is running on an actual device. Ref:
My game starts off by showing an intro video, after which it loads the main menu and plays a song. Below is the creation and execution of the song.
try
{System.out.println("?????????? create and play");
menuSong = MediaPlayer.create(this, R.raw.kindergarten_ska);
menuSong.setLooping(true);
menuSong.start();
}
catch (Exception e)
{
System.out.println("??????????? caught");
}
The error A/libc(1898): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1) is thrown during MediaPlayer.create(). The annoying part is that instead of catching the error, the app goes back to the intro! Which then ends up in an infinite loop. Which means there's nothing (As far as I can see) I can do to handle the error.
Also, this error occurs when trying to run from my 4.0.4 tablet. It works just fine on my 2.2.1 phone.
An error like this would lead me to believe that something is null, but the only thing possible in this case is the R value. It's an ogg file so I don't see why it wouldn't work on the tablet.
Also interesting is that this is the only MediaPlayer usage where it crashes. MediaPlayer works just fine elsewhere in the code.
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.