我想要一个按钮负责播放和暂停音乐。我还想根据其状态更改按钮背景。 当我点击"播放"音乐开始播放,背景图像变为"暂停"。 当我点击"暂停"音乐不会停止播放,但背景图像会再次改变为播放"
当我将mediaPlayer.stop()设置为另一个按钮(不是相同的)时,我检查它是否有效,并且它有效。
public boolean isplaying=false;
public void onClick(View view)
{
int clickedViewId = view.getId();
switch(clickedViewId){
case R.id.time_playButton:
{
playpauseButton = (Button) findViewById(R.id.time_playButton);
mediaPlayer = MediaPlayer.create(this,R.raw.time);
if(isplaying==false){
start();
return;
}
else {
stop();
return;
}
}
case R.id.time_ytButton:
//if I write here
//mediaPlayer.stop()
// it working well but this button is for other thing
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=JwYX52BP2Sk")));
}
}
public void start(){
playpauseButton.setBackgroundResource(R.drawable.pause);
mediaPlayer.start();
isplaying=true;
}
public void stop(){
playpauseButton.setBackgroundResource(R.drawable.play);
mediaPlayer.stop();
Toast.makeText(songs.this, "Checking if mediaPlayer.stop() is calliing on and it is but don't know why isn't work", Toast.LENGTH_SHORT).show();
isplaying=false;
}