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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -