0
我正在構建一個應用程序,其中播放音頻時圖像開始變化。 當音頻播放(開始)onclick按鈕時,圖像也開始改變不同的延遲,我也可以暫停我的音頻。我現在面臨和越來越迷惑的問題是,當我停下我的聲音,音頻暫停時暫停變化的圖像
如何暫停我的圖片一樣,所以,當我再次單擊該按鈕,我的聲音簡歷和圖像開始下一個改變從他們被暫停的地方。
private Button btn_play;
MediaPlayer mp;
int duration;
private ImageView imageView;
Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_names);
int resID = getResources().getIdentifier("audio", "raw", getPackageName());
mp = MediaPlayer.create(NamesOfALLAH.this, resID);
duration = mp.getDuration();
btn_play = (Button) findViewById(R.id.btn_play);
imageView = (ImageView) findViewById(R.id.imageView_Names);
btn_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mp.isPlaying()) {
mp.pause();
btn_play.setText("Play");
} else {
mp.start();
btn_play.setText("Pause");
changeImage1();
changeImage2();
changeImage3();
changeImage4();
changeImage5();
}
}
});
}
public void changeImage1() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageView.setImageResource(R.drawable.a1);
}
}, 6000);
}
public void changeImage2() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageView.setImageResource(R.drawable.a2);
}
}, 8000);
}
public void changeImage3() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageView.setImageResource(R.drawable.a3);
}
}, 10000);
}
public void changeImage4() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageView.setImageResource(R.drawable.a4);
}
}, 11000);
}
public void changeImage5() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageView.setImageResource(R.drawable.a5);
}
}, 12000);
}
`