Android let one media player stop the other -


i develop app , because doesn't sound good, if 2 sounds overlay, want make sound stop when next 1 playing. tried that

button1:

 mediaplayer mediaplayerw = mediaplayer.create(getbasecontext(), r.raw.w1);                     if(mediaplayerw.isplaying()){                  mediaplayerw.stop();}                 else{                  mediaplayerw.start();                 } }   

button2:

mediaplayer mediaplayerw = mediaplayer.create(getbasecontext(), r.raw.w2);                      if(mediaplayerw.isplaying()){                  mediaplayerw.stop();}                 else{                  mediaplayerw.start();                 } }   

the problem is, mplayer gets new id , therefore doesn't stop "old" sound.

then tried setdatasource still had create new objects of mediaplayer, ids still changed.

anyone idea that?

your solution not scalable , not efficiently fit needs.

android designed solution address issue facing : audiofocus apis.

this solution more scalable, work virtually infinite number of mediaplayer objects , have benefit of working across applications.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -