2017-02-10 3 views
1
image = (ImageView) findViewById(R.id.imageView16); 
     button = (Button) findViewById(R.id.btncheck); 
final MediaPlayer true_answer = MediaPlayer.create(this, 

R.raw.answer_is_true); 
    button.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        true_answer.start(); 
        if (true_answer.isPlaying()){//doesn't work 
         image.setBackgroundResource(R.drawable.anim); 
         AnimationDrawable animation = (AnimationDrawable)image.getBackground()Q; 
         animation.start(); 
        } 
        image.setBackgroundResource(R.drawable.anim); 
        AnimationDrawable animation = (AnimationDrawable)image.getBackground(); 
        animation.stop(); 
       } 
      }); 

私は関数isRunningを使用していますか?または私は追加する必要があります。私はこの問題を解決できません。私はメディアプレイヤーの実行中にアニメーションを開始するにはどうしたらいいですか? mediaplayerが実行されていない場合、アニメーションも実行されません

答えて

0

あなたの活動やフラグメントが活動MediaPlayer.OnCompletionListener

mediaPlayer.setOnCompletionListener(これ)を実装して実装する必要があります助けてください。これを登録できます。

メディアを停止できる完全なコールバックを開始します。

@Override 
    public void onCompletion(MediaPlayer mp) { 
     animation.stop(); 
    } 
+0

あなたは私に完全なコードを書くことができます –

+0

すべてのものをやっているところで、完全なアクティビティコードを追加してください。 –

関連する問題