John
John

Reputation: 1457

android.media.MediaPlayer crashes without exception

The MediaPlayer makes my app freeze without throwing an exception when I pass corrupted audio files to it. Here's my code:

try
{
    if (this.mediaPlayer.isPlaying())
    {
        this.mediaPlayer.reset();
    }

    this.mediaPlayer.setDataSource(this.currentSong.getFile() /* path string */);
    this.mediaPlayer.prepare();
    this.mediaPlayer.start();
}
catch (Exception e)
{
    Log.v("Oh snap", "MediaPlayer exception: " + e.toString());
}

What can I do about this? I need an exception to handle corrupted files properly. The test device is a Samsung Galaxy S2 running Android 2.3.6 and I'm targeting API level 8.

I'm not sure what's wrong with the corrupted flac files that I'm passing to the MediaPlayer. All I know is that they crash my app and the stock music player too, which shouldn't happen.

Upvotes: 0

Views: 1472

Answers (1)

Reuben Scratton
Reuben Scratton

Reputation: 38707

If it's a native crash there's very little you can do just from the Java layer. Check this answer for a slightly scary guide to the frightful hacking you'd need to do.

Upvotes: 1

Related Questions