如何让Soundpool加载很多短音?

时间:2015-04-29 07:41:42

标签: android stream soundpool

我得到的建议是,我应该使用Soundpool而不是Mediaplayer来点击按钮点击很多短音,但我真的不明白如何让它工作。这是我的代码:

protected void onCreate(Bundle buttons) {
    super.onCreate(buttons);
    setContentView(R.layout.activity_main);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    //SoundPool initialization somewhere
    SoundPool pool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

    //Load your sound effect into the pool
    int soundId = pool.load(this, R.raw.SOUND, 1); (How to load more sounds?)

    List<Integer> streams = new ArrayList<Integer>();

    Button PLAY= (Button)findViewById(R.id.PLAY);
    PLAY.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            int streamId = pool.play(SOUND, 1.0f, 1.0f, 1, 0, 1.0f);
            streams.add(streamId);
        }
    });

    Button stop = (Button)findViewById(R.id.stop);
    stop.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            for (Integer stream : streams) {
                 pool.stop(stream);
            }
            streams.clear();
        }
    });
}
  1. 我的代码不起作用。请编辑代码并将其发布到答案中。
  2. 我想加载更多声音。怎么样?
  3. youtube上有解释视频吗?

0 个答案:

没有答案