I everyone, I'm trying to make a simple piano application, for each note I have a .wav file and I'm using soundpool class to make It play.
BUT
On a couple of Xiaomi devices and on Asus zenfone a kind of white noise is all I can hear and it's very annoying, also despite my effort I couldn't find any solution on the web, help me please!! ))
Here my declaring of aAttributes and soundPool objects in class scope:
private SoundPool soundPool;
private AudioAttributes aAttributes;
volumeNote = 1.0f;
volumeFeedBack = 0.6f;
here the code on onCreate method:
aAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_GAME)
.build();
soundPool = new SoundPool.Builder()
.setMaxStreams(10)
.setAudioAttributes(aAttributes)
.build();
here an example of the code on the onClick method:
case R.id.btFaLow:
soundPool.play(faL,volumeNote,volumeNote,0,0,1);
break;
I hope these information can help to find the issue. Thank You all in advance!
There are some practical advises on the link below.
Android can't play some wav file with soundpool?
Personally, I've used Soundpool with .mp3 files with no white noise issues.
After some searching, I've found this link where CONTENT_TYPE_SONIFICATION is used instead of CONTENT_TYPE_MUSIC, which I believe may be more suited to what you're looking for.
Content type value to use when the content type is a sound used to accompany a user action, such as a beep or sound effect expressing a key click, or event, such as the type of a sound for a bonus being received in a game.
You can also checked out the code samples at coding in flow: https://codinginflow.com/tutorials/android/soundpool (I'm not associated with the site.)