How to stop playing a Sound via Soundpool?

对着背影说爱祢 提交于 2019-12-01 18:54:31

The method stop() takes the stream ID of a currently playing stream, not the sound ID you have loaded. So something like this:

int streamId = soundPool.play(soundID, volume, volume, 1, 0, 1f);

soudPool.stop(streamId);
streamId = soundPool.play(soundID, volume, volume, 1, 0, 1f);

Would stop the currently playing track and start another. A second option would be to limit the number of streams your SoundPool allows. If you instantiate your SoundPool with a maxStreams value of 1, then any currently playing sound will stop when you attempt to start another, which may implement your desired behavior more cleanly.

Quang Long

You Can See Code

public static void clear() {
        if (mSoundManager != null) {
            mSoundManager.mSoundPool = null;
            mSoundManager.mAudioManager = null;
            mSoundManager.mSoundPoolMap = null;
        }
        mSoundManager = null;
    }

I did it by loading the soundpool track id again..

mSoundPool.Stop(trackID);
trackID.load(getApplicationContext(),R.raw.audioclip,1;

And you can again play the mSoundPool.play() anyWhere.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!