简体   繁体   中英

Android SoundPool problem on some devices

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_SONIFICATION

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.)

FWIW, experienced the same problem on a Xiaomi Redmi 6, and @Peppinhood's suggestion to use .mp3 did the trick

For some reason, both .m4a and .wav produced heavily distorted sounds on that device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM