这是两个音频和视频队列。我希望他们重复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);
}
}
答案 0 :(得分:0)
播放音频和视频的过程非常简单,所以如果你只是制作一个循环,你最终会同时播放7次声音。您可以在播放结束时触发重复,例如声音,通过递减计数器并在计数器达到0时停止重复。