Soundpool,如何停止播放的声音?

时间:2016-09-28 14:13:43

标签: java android

我已阅读其他帖子,但我仍然不明白如何停止播放的声音,我希望当我按下按钮时会播放声音,当我按下另一个时按钮我希望声音停止播放,如果有人能帮助我那将会很棒。

1 个答案:

答案 0 :(得分:3)

您需要创建一个Stream ID并调用stop()方法,如下所示:

cmdkey /add:Domain:interactive=$computer_name\$username1 /user:$computer_name\$username1 /pass:$password

cmdkey /list

# created by CMDKEY
Target: Domain:interactive=$computer_name\$username1
Type: Domain Password
User: $computer_name\$username1

# created by RUNAS
Target: Domain:interactive=$computer_name\$username2
Type: Domain Password
User: $computer_name\$username2

以及如何停止声音:

SoundPool soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

static int StreamID;
static int Sound;

Sound = soundPool.load(this, R.raw.sndRes, 1);
...

btnStart.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        StreamID = soundPool.play(Sound, 1, 1, 0, 0, 1);
    }
});