Skip to content

Instantly share code, notes, and snippets.

@tluyben
Last active December 16, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/5472601 to your computer and use it in GitHub Desktop.
Save tluyben/5472601 to your computer and use it in GitHub Desktop.
Monkey SoundPool repeat trying in a Thread.
// add on top of gxtkAudio
class PlaySampleThread extends Thread {
SoundPool pool;
gxtkSample sample;
gxtkAudio.gxtkChannel chan;
float lv, rv;
int loops;
public PlaySampleThread(SoundPool pool, gxtkSample sample, gxtkAudio.gxtkChannel chan, float lv, float rv, int loops) {
this.pool = pool;
this.sample = sample;
this.chan = chan;
this.lv = lv;
this.rv = rv;
this.loops = loops;
}
public void run() {
for( int i=0;i<100;++i ){
chan.stream=pool.play( sample.sound,lv,rv,0,loops,chan.rate );
if( chan.stream!=0 ){
chan.state=1;
return;
}
try{
Thread.sleep( 100 );
}catch( java.lang.InterruptedException ex ){
}
}
}
}
// and change gxtkAudio.PlaySample to
int PlaySample( gxtkSample sample,int channel,int flags ){
gxtkChannel chan=channels[channel];
if( chan.stream!=0 ) pool.stop( chan.stream );
float rv=(chan.pan * .5f + .5f) * chan.volume;
float lv=chan.volume-rv;
int loops=(flags&1)!=0 ? -1 : 0;
new PlaySampleThread(pool, sample, chan, lv, rv, loops).start();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment