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.
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'm making an Audio Player app that will load some predefined audios from inside its raw resource folder.
I've sent the test APK for some people to test it, and it worked on 99% of the cases. But then, I started to get some crash reports on Crashlytics for a single device, the OnePlus A5000, running Android 8.1.0.
The stacktrace on crashlytics is as follows:
Fatal Exception: java.lang.IllegalStateException
at android.media.MediaPlayer._setDataSource(MediaPlayer.java)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1270)
at com.example.home.MediaPlayerHolder.loadMedia(MediaPlayerHolder.kt:56)
at com.example.home.HomePresenter.playSound(HomePresenter.kt:26)
at com.example.home.HomeFragment.onPlaySelected(HomeFragment.kt:178)
at com.example.home.SoundItemAdapter$ViewHolder$bind$1.onClick(SoundItemAdapter.kt:30)
package names were changed for privacy reasons
This is happening almost every time he clicks on the sound item play button. It also happens on the first time he clicks on any sound item.
I've tried to reproduce this crash on some devices, all of then have API <= 25, but I had no success doing so. All of them ran without an issue. I'm clueless of the probable cause of this error, or even if it's an edge case problem, or if there's indeed something wrong with my code.
This is how I'm loading the audio on the MediaPlayer:
if (mediaPlayer?.isPlaying == true) {
mediaPlayer?.release()
mediaPlayer = null
}
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer()
}
val fileDescriptor = context.resources.openRawResourceFd(resource)
mediaPlayer?.setDataSource(fileDescriptor.fileDescriptor, fileDescriptor.startOffset, fileDescriptor.length)
fileDescriptor.close()
mediaPlayer?.prepare()
mediaPlayer?.start()
The reason was you can't start services in the background anymore after API 26. So you have to start ForegroundService above API 26.
I am trying to add functionality to extract, decode, edit, encode and mux a video on Android. Therefore, I found some very useful implementation, which is part of the Android CTS ExtractDecodeEditEncodeMuxTest. Unfortunately, the code only works if it is executed as part of the testcase. I tried to execute it from a normal activity and get:
E/ExtractDecodeEditEncodeMuxTest (18781): java.lang.IllegalStateException:
Failed to stop the muxer
W/System.err(18781): java.lang.RuntimeException:
Surface frame wait timed out
W/System.err(18781): at ...OutputSurface.awaitNewImage(OutputSurface.java:216)
Any ideas, why the output surface does not receive the frames?
UPDATE:
Here are the log files for the working test case and the non-working implementation. The code for both is exactly the same. The only difference is that the working one is an AndroidTestCase and the other one is running in the application within an IntentService.
It seems that the whole thing stops extracting and decoding after about 6 frames. Any ideas?
Working Testcase Logoutput
Non-Working Log Output
morelikely you need to run it in separate thread
public static void runTest(ExtractDecodeEditEncodeMuxTest test) throws Throwable {
test.setOutputFile();
TestWrapper wrapper = new TestWrapper(test);
Thread th = new Thread(wrapper, "codec test");
th.start();
th.join();
if (wrapper.mThrowable != null) {
throw wrapper.mThrowable;
}
}
Thank's to fadden, I was able to resolve this issue. I am using an intent service now and start a thread without looper there, which works fine.
For running the code in an Android service, this means that the wrapping thread has to be started from a custom thread. Starting a thread within a thread is probably not the very best solution, but it actually solves the problem.
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
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.