这是两个音频和视频队列。我希望他们重复 7 次。
但是 for 循环和 while 循环不起作用。似乎所有的信誉都会并行执行。
我也能回忆起Activity
。
但我想要一种方法来调用音频和视频本身多次(例如 7 次)一个接一个。
任何帮助表示赞赏。
这是我的代码的一部分:
Public boolean dispatchTouchEvent(MotionEvent ev) {
SharedPreferences appSettings = PreferenceManager.getDefaultSharedPreferences(this);
boolean doAudio= appSettings.getBoolean("audioCue", true);
boolean doVideo= appSettings.getBoolean("videoCue", true);
String audioFreqS = appSettings.getString("audioFrequency", "400");
float audioFrequency = (float)Integer.parseInt(audioFreqS);
String audioLoudnessS = appSettings.getString("audioLoudness", "100");
float audioLoudness = ((float)Integer.parseInt(audioLoudnessS))/100.0f;
// determine whether estimation or cue mode is active
if (!currentlyEstimating) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// determine random timespan for cue(s)
initCueLength();
// use video cue, i.e. display colored block for the specified time
if (doVideo) {
switch (Integer.parseInt(appSettings.getString("cueBackgroundColor", "1"))) {
case 1:
videoLayout.setBackgroundColor(Color.WHITE);
break;
case 2:
videoLayout.setBackgroundColor(Color.RED);
break;
case 3:
videoLayout.setBackgroundColor(Color.GREEN);
break;
case 4:
videoLayout.setBackgroundColor(Color.BLUE);
break;
case 5:
videoLayout.setBackgroundColor(Color.YELLOW);
break;
default:
videoLayout.setBackgroundColor(Color.WHITE);
}
// after the delay specified for postDelayed, set background to black
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
videoLayout.setBackgroundColor(Color.BLACK);
}
}, cueLength);
loopnum++;
}
if (doAudio) {
// TODO integrate sound playing
final SoundGenerator task=new SoundGenerator();
task.keepPlaying(true);
task.setLoudness(audioLoudness);
// start sound generator with the specified frequency (Hz)
task.execute(audioFrequency);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
task.keepPlaying(false);
}
}, cueLength);
}
}