Почему я продолжаю получать эту ошибку при попытке использовать звуковой пул? - PullRequest
0 голосов
/ 07 марта 2019

Я следую документации по 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);

    }


}

1 Ответ

0 голосов
/ 07 марта 2019

Вам нужно изменить определенный класс с SoundPool на MySoundPool или другое имя, чтобы избежать конфликта с SoundPool классом в Android.

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();
    }
}
...