從加速度計值和設備平坦時,我有以下「條件」,連續播放嘟嘟聲。我無法弄清楚如何在指定的時間段內(例如: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();
}
}