开发者

Stop sound running through infinite loop

I am playing a sound infinite time using foll开发者_Go百科owing code

SoundPool sounds = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);  
beepSound = sounds.load(this, R.raw.beep, 1);  
beepSoundStream = sounds.play(beepSound, 1.0f, 1.0f, 0,-1, 1.5f);  

On some event i want to stop the sound. I am trying

sounds.stop(beepSoundStream);  

I have also tried

sounds.stop(beepSound)  

But it is not working.


You have your play method set to loop. Change the fifth argument to a 0...

beepSoundStream = sounds.play(beepSound, 1.0f, 1.0f, 0, 0, 1.5f);


sounds.autoPause() works for me.


idSound = soundPool.play(soundId, 1, 1, 1, -1, 1f);

and for stop soundPool:

new android.os.Handler().postDelayed(
                new Runnable() {
                    public void run() {
                        soundPool.stop(idSound);
                    }
                }, 100);

after much trying..this solution works for me!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜