Soundpool sample not ready

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

    This would work for you definitely !

    public void playWavFile() {
    
        Thread streamThread = new Thread(new Runnable() {           
    
            @Override
            public void run() {                 
                SoundPool soundPool;
                final int wav;
                String path = "/mnt/sdcard/AudioRecorder/record.wav";
                soundPool = new SoundPool(5,AudioManager.STREAM_MUSIC, 0);
                wav = soundPool.load(path, 1);
                soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                    @Override
                    public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                        // TODO Auto-generated method stub
                        soundPool.play(wav,100, 100, 0, 0, 1f);
                    }
                });
    
            }        
        });
    
        streamThread.start();
    }   
    

提交回复
热议问题