【问题标题】:I want to play two sounds in background one after another in android我想在android中一个接一个地在后台播放两种声音
【发布时间】:2012-01-22 14:11:16
【问题描述】:
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();

我已经尝试了很多东西,但这是最近的,但这甚至不起作用

【问题讨论】:

    标签: android audio


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多