我按照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);
}
}
您需要将定义的类从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();
}
}