2
SoundPool에서 mp3 파일을 실행하려고합니다. SoundPool.load로 mp3를로드했지만 SoundPool.play를 시도해도 작동하지 않으며 예외가 발생하지 않습니다. API21을 사용하고 있습니다.SoundPool이 MP3를 재생하지 못합니까?
어떻게 해결할 수 있습니까?
나는 이것을 시도하고있다.
public class CustomSoundPool {
//SDK Version
public SoundPool getSoundPool(){
SoundPool sounds = null;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
AudioAttributes attributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_GAME)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
sounds = new SoundPool.Builder()
.setAudioAttributes(attributes)
.build();
}else{
sounds = new SoundPool(5,AudioManager.STREAM_MUSIC,0);
}
return sounds;
}
}
/** play sound with error or success */
private void playSound(){
SoundPool sound = new CustomSoundPool().getSoundPool();
if(resposta.getValor() == 1){
int soundId = sound.load(getView().getContext(), R.raw.sucesso, 1);
sound.play(soundId, 1, 1, 0, 0, 1);
}else{
int soundId = sound.load(getView().getContext(), R.raw.erro, 1);
sound.play(soundId, 1, 1, 0, 0, 1);
}
sound.release();
}
나는 제안을해도 작동하지 않습니다. 소리가 실행되지 않으면 재생 – FernandoPaiva
편집 된 답변보기. –
이 정상적으로 작동합니다. 고마워요! – FernandoPaiva