Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AsyncTask in LibGDX - example

Did anyone used AsyncTask with AsyncResult and AsyncExecutor in LibGDX? I want to run some audio recording and processing asynchronously with checking if result is ready. This is part of my code:

private FftAnalysis analysis;
private AsyncExecutor executor;
private AsyncResult<Double> asyncResult;
(...)
public GameWorld(int midPointY) {
  executor = new AsyncExecutor(300); // I know how big this value is.
  analysis = new FftAnalysis();
  asyncResult = executor.submit(analysis);
}
public void update(float delta){
if(asyncResult.isDone()){ 
   freq = asyncResult.get();
   asyncResult = executor.submit(analysis);
}

The isDone() is never true and I don't see function call() from FftAnalysis ever executed...

What am I doing wrong?

like image 783
Rafał Praczyk Avatar asked Jan 24 '26 21:01

Rafał Praczyk


1 Answers

Why not just using the libgdx api to do that? Have a look at the Timer class and Task class here: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Timer.html .

Basically you can run your code in a separate thread and get the result when it is finished.

like image 59
Daniele Avatar answered Jan 26 '26 13:01

Daniele