Android 在特定时间内播放循环声音
我想在屏幕提示Android 在特定时间内播放循环声音,android,loops,audio,alert,android-alarms,Android,Loops,Audio,Alert,Android Alarms,我想在屏幕提示alertDialog时播放声音 直到用户点击它的按钮 每x秒它就会播放另一个声音。 (与一般警报类似,但声音不断变化) 我试着使用mediaPlayer,但不知道如何一个接一个地播放声音 我怎么做? 这是我的警报代码: AlertDialog.Builder alertDialog3 = new AlertDialog.Builder(MainActivity.this); //Setting Dialog noise mediaPlayer = MediaPl
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();
您可以使用SoundPool,然后根据需要加载和播放任意多的声音:
SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
int sound1 = soundPool.load(this, R.raw.house_fire_alarm, 1);
int sound2 = soundPool.load(this, R.raw.house_fire_alarm1, 1);
....
soundPool.play(sound, 1.0f, 1.0f, 0, 0, 1.0f);
谢谢你的评论,但我仍然有同样的问题,我怎么能表明第一个是完成的,第二个是完成后,我寻找一些东西,我把一个声音文件,它就像播放列表。。是否可以使用
声音池
?