Reputation: 834
I made an Android Application that plays certain sounds. I want to stop a sound, if the next one is playing and I successfully made that with
public void w1() throws IllegalArgumentException, SecurityException, IllegalStateException, IOException{
mediaPlayerW.reset();
mediaPlayerW.setDataSource(MainActivity.this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.w1));
mediaPlayerW.prepare();
mediaPlayerW.start();}
public void onClick(View f) {
if(f == button1)
{w1();}}
[the other methods are called w2; w3; w4 (...)] but let us just work on one sound.
That works so far, every button sound can "choke" itself (and start to play again from the beginning) and he stops others so always ONLY the "new" sound plays.
The problem I got now is, that i have a little interruption (~100ms) if I press a button. Even 40ms would be too high for a music application. Is it possible to preload the sounds in cache or something? I think the .reset() takes most of the time..
Thx for your help
Upvotes: 0
Views: 108
Reputation: 834
Ok I found out that this latency problem can't be solved for older versions, but since Android 4.1 there is another audio driver that works much better. I tried with my gTab 2.0 and the feedback is really fast.
You don't have to set anything different, the new audio stuff in 4.1 works like the previous ones, but MUCH faster
Upvotes: 1