audio - Android Musicplayer play same sound more than one at atime -
private mediaplayer mpintro; mpintro = mediaplayer.create(this, r.raw.bgmusic); mpintro.setlooping(true); mpintro.start();
these mediaplayer code plays in app background continuously, altough ı have small problem that. when app in background or close (without force close) still plays sound, launch again plays twice , everytime more. how can stop or pause , 1 sound?
ps:i not want sound file in app apk, how can call folder?
in main activity handle example override onpause(), onstop() methods. if develop in eclipse, push right mousebutton-->source-->override/implement methods. here choose onpause() or onstop() method , added code:
@override protected void onpause(){ if(mpintro!=null){ mpintro.stop(); } super.onpause(); }
same onstop(). depends on want. if want stop mediaplayer, should work. if want pause player, play again if resume app, call:
@override protected void onpause(){ if(mpintro!=null){ mpintro.pause(); } super.onpause(); }
and in onresume():
@override protected void onresume(){ if(mpintro!=null){ mpintro.start(); } super.onresume(); }
i couldn´t test code now, if wrong, , give try later. should give example how handle it.
Comments
Post a Comment