Note that there are some explanatory texts on larger screens.

plurals
  1. POLags while playing 2 sounds on the same time in timer
    primarykey
    data
    text
    <p>I have a small app that basically sets up a <strong>timer</strong> and plays <strong>sets of 2 sounds one after another</strong>.</p> <p>I've tried 2 timers, because I wanted both sounds to start exactly at the same time each time. I gave the app 500ms for setting both timers before they start</p> <pre><code> Calendar cal = Calendar.getInstance(); Date start = new Date(cal.getTime().getTime() + 500); timerTask1 = new TimerTask() { //1st timer @Override public void run() { soundManager.playSound(1); } }; timer1 = new Timer(); timer1.schedule(timerTask1, start, 550); timerTask2 = new TimerTask() { //2nd timer @Override public void run() { soundManager.playSound(2); } }; timer2 = new Timer(); timer2.schedule(timerTask2, start, 550); } </code></pre> <p>soundManager is a <strong>SoundManager</strong> object which is based on <a href="https://stackoverflow.com/questions/3039078/playing-multiple-sounds-using-soundmanager/3763993#3763993">this tutorial</a>. Thew only change I've made was decreasing number of avalible streams from 20 to 2 since I play only 2 sounds at the same time.</p> <p>Now the problem. <strong>It's not playing at the equal rate</strong> neither on my Motorola RAZR or the emulator. The app slows sometimes, making a longer brake than desired. I can't let that happen. What could be wrong here?</p> <p>I'm using very short sounds in <strong>OGG</strong> format</p> <p>EDIT: I've made some research. Used 2 aproaches. I was measuring milisecond distances between sound was fired. Refresh rate was 500 ms.</p> <ul> <li>1st aproach was TimerTask - it is a big fail. It started at 300ms, then was constantly growing, and after some time (2 mins) stabilized at 497ms which would be just fine if it started as that.</li> <li>2nd aproach was while loop on AsyncTask - it was giving me outputs from 475 to 500ms which is better than TimerTask but still inaccurate</li> </ul> <p>At the end none of aproach was playing smoothly. There were always lags</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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