为什么我在尝试使用声音池时会一直收到此错误?

问题描述 投票:-1回答:1

我按照Android文档创建一个声音池,它不断给我这个奇怪的消息。我不知道为什么。消息显示:SoundPool中的SoundPool()无法应用于:预期参数:实际参数:

context:
android.content.Context
3  (int)


AudioManager.STREAM_MUSIC  (int)

0  (int)

public class SoundPool {

    private static SoundPool soundPool;
    private static int sound;

    public SoundPool(Context context) {
        soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);

    }


}
android soundpool
1个回答
0
投票

您需要将定义的类从SoundPool更改为MySoundPool或其他名称,以避免与Android中的SoundPool类冲突。

public class MySoundPool {

    private static SoundPool soundPool;
    private static int sound;

    public MySoundPool(Context context) {
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setLegacyStreamType(AudioManager.STREAM_MUSIC)
                .build();

        soundPool = new SoundPool.Builder()
                .setMaxStreams(3)
                .setAudioAttributes(audioAttributes)
                .build();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.