Search code examples
androidmedia-playermidi

Media Player crash after use


I am working on a small application that plays back eight different .5 second midi files. I have an ontouch action that gets called everytime a specified object gets touched and within that I have an if/else if statement that plays the specified midi file depending on the object touched. When I run this, It works fine for the first several touches but after a while the playback stops, and then the app eventually crashes. What is going wrong here?

Basic Structure:

public ontouch(){   
    if (something >= 3){  
         mediaplayer s = mediaplayer.create(somethingmidi2);  
         s.start();  
    }else if (something < 3){
         mediaplayer s = mediaplayer.create(somethingmidi);  
         s.start();  
    }
 } ` 

Solution

  • Just a guess, but you probably aren't calling the release() method of the media player, nor reset() when you are reinitializing it.