Soundpool sample not ready

后端 未结 8 1093
孤独总比滥情好
孤独总比滥情好 2020-12-09 03:15

I have a .wav file that I\'d like to use across my game, currently I am loading the sound in onCreate() of each activity in the game.

 soundCoun         


        
8条回答
  •  庸人自扰
    2020-12-09 03:52

    you should use setOnLoadCompleteListener if possible ... if not, wrap a while loop around your call to 'play'. something like:

    int waitLimit = 1000;
    int waitCounter = 0;
    int throttle = 10;
    while(soundPool.play(soundId, 1.f, 1.f, 1, 0, 1.f) == 0 && waitCounter < waitLimit)
     {waitCounter++; SystemClock.sleep(throttle);}
    

    this will retry 'play' 1000 times on a 10ms interval. this should be run on a non-ui thread of course, and is still not ideal. but maybe a little stronger than waiting an arbitrary time and expecting the pool to be ready.

提交回复
热议问题