你怎么防止它在android中运行不止一次的声音?

时间:2016-03-28 18:24:15

标签: android

当我点击按钮操作歌曲时,按下它再次操作互操作 如果再次按下再次启动声音,我怎么能不重叠?

public class Circal extends Activity {

    Button sound = (Button) findViewById(R.id.sound);
    sound.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MediaPlayer player = MediaPlayer.create(Circal.this,R.raw.one);
            player.start();
        }
    });
}

1 个答案:

答案 0 :(得分:1)

如果条件已经开始,则添加if条件

if(player.isPlaying()){
    player.pause(); // pause before doing anything
    player.seekTo(0); // go to 0 seconds
}
player.start()