开发者

Android SoundPool cutting sound file short

开发者 https://www.devze.com 2023-01-27 16:08 出处:网络
I\'m fairly new to Android so be gentle开发者_运维知识库! I have the following code, which should (I think) just play \"developersshort\".

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!


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消