我正在尝试让切换按钮播放歌曲但延迟。用户必须在数字字段(调色板/文本字段/数字)中输入分钟,这将用于设置延迟。我已经检查了 android 开发人员资源,但我仍然不知道从哪里开始。
目前我有这个:
public class Main extends Activity {
MediaPlayer mp;
Button startButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mp = MediaPlayer.create(getBaseContext(), R.raw.songthingy);
ToggleButton toggle = (ToggleButton) findViewById(R.id.ToggleButton);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
mp.start();
} else {
mp.stop();
}
}
});
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
}