我想从提示到屏幕开始播放声音,直到用户点击它的按钮,alertDialog
每隔 x 秒,它就会播放另一种声音。(像一般警报,但声音不断变化)
我尝试使用mediaPlayer
但不知道如何播放声音后的声音..
我该怎么做 ?这是我的警报代码:
AlertDialog.Builder alertDialog3 = new AlertDialog.Builder(MainActivity.this);
//Setting Dialog noise
mediaPlayer = MediaPlayer.create(this, R.raw.house_fire_alarm);
mediaPlayer.setLooping(true);
mediaPlayer.start();
// Setting Dialog vibrate
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern= {100, 1000};
vibrator.vibrate( pattern ,0);
// Setting Dialog Title
alertDialog3.setTitle("reminder:");
// Setting Dialog Message
alertDialog3.setMessage("dont forget");
// Setting Icon to Dialog
alertDialog3.setIcon(R.drawable.ic_launcher);
// Setting Cancelable
alertDialog3.setCancelable(false);
// Setting Positive Button
alertDialog3.setPositiveButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.release();
}
mediaPlayer = null;
if (vibrator.hasVibrator()){
vibrator.cancel();
vibrator = null;
}
......
finish();
}
});
// Setting Negative Button
alertDialog3.setNegativeButton("Rate us", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke RateUs event
if (mediaPlayer.isPlaying()) {
mediaPlayer.release();
}
mediaPlayer = null;
if (vibrator.hasVibrator()){
vibrator.cancel();
vibrator = null;
}
//open browser in activity to app page in google play
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName() ) ) );
}
});
// Showing Alert Message
alertDialog3.show();