Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使声音池加载大量短声音?_Android_Stream_Soundpool - Fatal编程技术网

Android 如何使声音池加载大量短声音?

Android 如何使声音池加载大量短声音?,android,stream,soundpool,Android,Stream,Soundpool,我得到的建议是,我应该使用Soundpool而不是Mediaplayer来播放按钮点击时发出的许多短声音,但我真的不知道如何让它工作。这是我的密码: protected void onCreate(Bundle buttons) { super.onCreate(buttons); setContentView(R.layout.activity_main); setVolumeControlStream(AudioManager.STREAM_MUSIC);

我得到的建议是,我应该使用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();
        }
    });
}
我的代码不起作用。请编辑代码并将其发布到answers。 我想加载更多的声音。怎样 youtube上有解释视频吗?
pool.play的第一个参数是什么?我想是soundID。int soundID=pool.load是什么。。。它与声音变量有何关系?即使我将int-soundID与pool.play中的第一个参数匹配,它也表示.add-in-streams.addstreamId:无法解析方法我不明白您的意思。。。