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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -