我想在android中一个接一个地播放背景中的两个声音

时间:2012-01-22 04:36:38

标签: android audio

dogIntroSound =  MediaPlayer.create(AnimalPiker1.this, R.raw.introdog);
dogIntroSound.start();

Thread timer = new Thread(){
    public void run(){
        try{
            sleep(5000);
        } catch (InterruptedException e){
            e.printStackTrace();
        }finally{
            dogSound =  MediaPlayer.create(AnimalPiker1.this, R.raw.dog);
            dogSound.start();

        }
    }
};

timer.start();

我尝试了很多东西,但这是最新的,但这甚至无效

1 个答案:

答案 0 :(得分:1)

使用setOnCompletionListener:

dogIntroSound =  MediaPlayer.create(AnimalPiker1.this, R.raw.introdog);
dogIntroSound.setOnCompletionListener(new OnCompletionListener() {

   public void onCompletion(MediaPlayer mp) {
     dogSound =  MediaPlayer.create(AnimalPiker1.this, R.raw.dog);
     dogSound.start();
   }

});

dogIntroSound.start();