Soundpool sample not ready

后端 未结 8 1094
孤独总比滥情好
孤独总比滥情好 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:54

    The SoundPool library uses the MediaPlayer service to decode the audio into a raw 16-bit PCM mono or stereo stream which we simply can call preparation of Stream, that takes some times depending on size of sound file. And if we try to play the sound before that process is over, we get "sample x not ready" error.

    There are two solutions for this

    1. implement setOnLoadCompleteListener or
    2. wait arbitrary amount of time so that preparation is over

    and then play it Note that there is no exception for this condition or application is not crashing without any try-catch

提交回复
热议问题