简体   繁体   中英

Android SoundPool cutting sound file short

I'm fairly new to Android so be gentle!

I have the following code, which should (I think) just play "developersshort".

public constructor(Context context){
    this.context = context;
    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC,0);
    soundPoolMap = new HashMap<Integer, Integer>();
    soundPoolMap.put(1, soundPool.load(this.context, 
        R.raw.developersshort, 1));         
}

public void run() {
    soundPool.play(soundPoolMap.get(1), 1, 1, 1, 0, 1f);
}

[To try to figure out what's going on, it currently plays that remix of Steve Ballmer shouting "developers" repeatedly! The sound file is ~90KB in size.]

When I run my app in the emulator, and press the button to trigger the sound, it says "developers developers developers..." etc etc, like I would expect.

However, when I deploy it to my phone, all I hear something like "velop" once, and then the sound stops.

I have NO idea what is going on, any ideas?

Thanks a lot!

Have you try with resampling the sound file ???

Before that my sound file getting cut. But i have converted and resample that m4a from 44KHz to 22KHz and now it works without getting cut. refer this : and again about memory issues with SoundPool

So try like same.

Hope it will works for you.

Is your audio file a .ogg file? It seems like other formats have issues with SoundPool. If that doesn't work you may want to test it with a smaller audio file. I had some glitches when my audio file was over 60kb.

60kb on storage, or 2mb on the heap, decoded, as pure wave MIGHT be the limits, yes. make sure you dont use anything longer than a second or something like that.

soundpool really needs small files. read the SDK page.

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