Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't understand "<strong>the timing is always off</strong>"? what does it mean?</p> <p>I am not so clear about your question and your description, but Is it true: You want to postpone the execution of a code block after some period of time?</p> <p>If it's the case, you must consider whether your <strong><code>new Handler().postDelayed(..)</code></strong> is called inside another UI thread or not. Try this if it's an activity's process:</p> <pre><code>your_activity_instance.runOnUiThread(new Runnable() { @Override public void run() { //delay with thread try{ Thread.sleep(1500); }catch(.....) {..} //your work load here } }); </code></pre> <p>NOTE: </p> <ul> <li><p>Handler.postDelayed() does NOT create a separated thread for your code block, but only append a new message (related to your Runnable instance) with timer sticker into current thread's message queue.</p></li> <li><p>activity.runOnUiThread() do the similar thing but the <strong><code>Runnable.run()</code></strong> has to wait until the system comes back to activity UI thread then be excuted. This's helpful when you want to do some activity's job in its child thread.</p></li> </ul> <p><strong>Update for modified question:</strong></p> <p>I may understand your intention: trying to execute <strong><code>wavPlayer.start()</code></strong> and <strong><code>mp3Player.start()</code></strong> at the same time; but your current solution is not nice or even it is impossible:</p> <ul> <li><p>In the same thread which you are using handlers, you will hardly sync the 2 functions (as I mention, handler.run() doesn't spawn separated thread).</p></li> <li><p>you can not pin down the exact time stamp of <strong><code>hanler.run()</code></strong> because the system controls when the message is appended to the queue, the post delayed is a relative value.</p></li> </ul> <p>My suggested solution:</p> <ul> <li><p>You spawn a separated thread for each player. </p></li> <li><p>Before each thread start(), you mark the time stamp (may use millisecs, not such of accuracy to use nano)</p></li> <li><p>In the second thread which is called later, you also pass to it the DELTA of time stamps (diff between markers). Then use <strong><code>Thread.Sleep()</code></strong> or <strong><code>Handler.postDelayed()</code></strong> for your adjustment of sync.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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