Note that there are some explanatory texts on larger screens.

plurals
  1. POPre-loading sound effects
    text
    copied!<p>I have the counter working (thanks for the help) and I have added sound using MediaPlayer, the problem is that there is a delay loading the counter because the sounds are loaded on the same class.</p> <p>Is there a way to pre-load the sounds using the main class, so then, when the counter is called, the numbers are buffered and can be called from this class?</p> <p>The application has a splash screen and the only purpose is to load anything needed by the other classes to avoid delays.</p> <p>If sounds can't be loaded from another class, could they be loaded individually at play time?</p> <p>This is what I have so far...</p> <pre><code>final boolean sound = timer_sound.getBoolean("timer_sound", true); final MediaPlayer number01 = MediaPlayer.create(this, R.raw.number_1); final MediaPlayer number02 = MediaPlayer.create(this, R.raw.number_2); final MediaPlayer number03 = MediaPlayer.create(this, R.raw.number_3); final MediaPlayer number04 = MediaPlayer.create(this, R.raw.number_4); final MediaPlayer number05 = MediaPlayer.create(this, R.raw.number_5); final MediaPlayer number06 = MediaPlayer.create(this, R.raw.number_6); final MediaPlayer number07 = MediaPlayer.create(this, R.raw.number_7); final MediaPlayer number08 = MediaPlayer.create(this, R.raw.number_8); final MediaPlayer number09 = MediaPlayer.create(this, R.raw.number_9); final MediaPlayer number10 = MediaPlayer.create(this, R.raw.number_10); final MediaPlayer number15 = MediaPlayer.create(this, R.raw.number_15); final MediaPlayer number20 = MediaPlayer.create(this, R.raw.number_20); lastSeconds = (TextView) findViewById(R.id.lastminuteseconds); lastMinute = new CountDownTimer(60 * 1000, 1000) { public void onTick(long secondsToStart) { int elapseTime = (int) (secondsToStart / 1000); if (sound == true){ switch(elapseTime) { case 1: number01.start();break; case 2: number02.start();break; case 3: number03.start();break; case 4: number04.start();break; case 5: number05.start();break; case 6: number06.start();break; case 7: number07.start();break; case 8: number08.start();break; case 9: number09.start();break; case 10: number10.start();break; case 15: number15.start();break; case 20: number20.start();break; } } </code></pre> <p>this is working almost fine, the problem is that there is a 2 second delay loading the files, and I wanted to add few more (50, 40, 30).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload