更新时间:2023-12-04 08:24:04
根据 http://developer.android.com/reference/android/media/MediaPlayer.html ,我想您可以执行以下操作:
According to http://developer.android.com/reference/android/media/MediaPlayer.html, I suppose you could do something like this:
Button two = (Button)this.findViewById(R.id.button2);
final MediaPlayer mp2 = MediaPlayer.create(this, R.raw.two);
two.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// If the music is playing
if(mp2.isPlaying() == true)
// Pause the music player
mp2.pause();
// If it's not playing
else
// Resume the music player
mp2.start();
}
});
您实际上可以只写
if(mp2.isPlaying())
代替
if(mp2.isPlaying() == true)
这只是为了了解正在发生的事情.
It's just for the sake of understanding what is going on.