Last active
December 16, 2015 17:48
-
-
Save tluyben/5472601 to your computer and use it in GitHub Desktop.
Monkey SoundPool repeat trying in a Thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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