从加速度计值和设备平坦时,我有以下“条件”,连续播放嘟嘟声。我无法弄清楚如何在指定的时间段内(例如:5秒)将此声音设置为重复。我尝试了很多方法,并始终保持声音始终播放或不遵循if条件。如果有人可以帮助我..提前感谢您..Android,在指定的时间段内重复动作
if (x > -0.1 && x < 0.1 && y > -0.1 && y < 0.1) {
try {
AssetFileDescriptor afd = getAssets().openFd("beep.wav");
mMediaplayer = new MediaPlayer();
mMediaplayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
mMediaplayer.prepare();
mMediaplayer.start();
mMediaplayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//mp.setLooping(false);
mp.stop();
mp.release();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}