media player - Android MediaPlayer can't stop -


i have code fragment in brocardcastreceiver this:

if (cmd != null && cmd.equals(play_sound)) {      log.i("mp", "mp has been prepared ");     mp.setlooping(true);      mp.start();       return; }  if (cmd != null && cmd.equals(stop_sound) && mp != null) {             if (mp.islooping()) {         mp.setlooping(false);     }      mp.stop();      mp.release();       return;  } 

it aims control alarming or stop alarming. can make mp run successfully, when want stop it, mp null. how can stop mp being changed?

try

in code

       stopplaying(); 

and declare methode .

 private void stopplaying() {     if (player1 != null) {          player1.stop();         player1.release();         player1 = null;    } } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -