Saturday, September 18, 2010

Version 1.6: Hotfix for force closure on Android 2.1

On some Android 2.1 devices there were force closures after three intervals being played in a row. Fixed!

Technical detail: The 2.1 MediaPlayer implementation seems just a little inconsistent.  Occasionally the MediaPlayer.create() call returns null.  Likely due to an improper release each time it was used.

Here's a snippet from the present, working code.

public void killMediaPlayer()
{
    if (mediaPlayer != null)
    {
        try
     {
         mediaPlayer.release();
     }
     catch(Exception e)
     {
         e.printStackTrace();
     }
    }
}

Ultimately called after the play button is pressed:

this.killMediaPlayer();

mediaPlayer = MediaPlayer.create(this.context, Consts.ChordResourceMap.chordMap.get(index));

if (mediaPlayer != null) mediaPlayer.start();

So, the obvious moral of the story is -- and clearly this is not new news -- API behavior will differ from OS version to OS version. In this case, 2.2 Froyo was forgiving with (lack) of release of the media player. 2.1 Eclair, intermittently, was not.

No comments:

Post a Comment