我目前正在eclipse中使用MediaPlayer,我发现如果我正在循环播放这首歌,我不能在我想要时暂停它。为了清楚起见,我将向您展示代码。
ToggleButton unu = (ToggleButton)this.findViewById(R.id.button1);
final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.ss);
unu.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// If the music is playing
if(mp1.isPlaying())
// Pause the music player
mp1.pause();
// If it's not playing
else
// Resume the music player
mp1.setLooping(true);
mp1.start();
}
});
为什么我不能暂停它的任何想法? 我正在尝试这样的事情
if(mp1.isPlaying())
// Pause the music player
mp1.pause();
mp1.setLooping(false);
// If it's not playing
else
// Resume the music player
mp1.setLooping(true);
mp1.start();
它给我错误说:令牌“else”上的语法错误,删除此令牌
答案 0 :(得分:0)
如Nfear所说,支架哪里缺失
if(mp1.isPlaying()) {
// Pause the music player
mp1.pause();
mp1.setLooping(false); }
// If it's not playing
else {
// Resume the music player
mp1.setLooping(true);
mp1.start(); }
添加括号解决了错误