我有5首歌的音乐播放列表。 我只希望在应用程序中使用时播放和停止按钮能够正常工作。并且我可以在想要停止音乐并开始另一首歌曲时停止音乐。
现在的情况是......音乐在PLAY按钮上播放,当我点击STOP按钮时它会停止,但是当我想要播放其他歌曲或同一首歌曲时,什么也不会发生。请帮帮我。
public class glavna extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MediaPlayer MPRadio1 = MediaPlayer.create(this, R.raw.pj1);
final MediaPlayer MPRadio2 = MediaPlayer.create(this, R.raw.pj2);
final MediaPlayer MPRadio3 = MediaPlayer.create(this, R.raw.pj3);
final MediaPlayer MPRadio4 = MediaPlayer.create(this, R.raw.pj4);
final MediaPlayer MPRadio5 = MediaPlayer.create(this, R.raw.pj5);
final RadioButton rb1, rb2, rb3, rb4, rb5;
rb1 = (RadioButton) findViewById(R.id.radio1);
rb2 = (RadioButton) findViewById(R.id.radio2);
rb3 = (RadioButton) findViewById(R.id.radio3);
rb4 = (RadioButton) findViewById(R.id.radio4);
rb5 = (RadioButton) findViewById(R.id.radio5);
Button btn = (Button) findViewById(R.id.buttonplay);
Button btnStop = (Button) findViewById(R.id.buttonStop);
btnStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View b){
MPRadio1.stop();
MPRadio2.stop();
MPRadio3.stop();
MPRadio4.stop();
MPRadio5.stop();
};
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(rb1.isChecked())
{
MPRadio1.start();
}
else
{
if(rb2.isChecked())
{
MPRadio2.start();
}
else
{
if(rb3.isChecked())
{
MPRadio3.start();
}
else
{
if(rb4.isChecked())
{
MPRadio4.start();
}
else
{
if(rb5.isChecked())
{
MPRadio5.start();
}
}
}
}
};
}
}
);}}