android studio怎么加入延迟,在Android Studio声音输出后添加延迟

我目前正在为Android编写我的第一个应用程序。我正在解析一个字符串并将值传递给一个开关。在Android Studio声音输出后添加延迟

传递到开关的值输出相应的声音。问题是它输出的所有声音在同一时间重叠在一起。

无论如何要在播放声音之后添加一个轻微的延迟来阻止这种情况的发生?

for(int j =0; j

{

int i = resultString.charAt(j);

switch(i) {

case '1':

one.start();

break;

case '2':

two.start();

break;

case '3':

three.start();

break;

case '4':

four.start();

break;

case '5':

five.start();

break;

case '6':

six.start();

break;

case '7':

seven.start();

break;

case '8':

eight.start();

break;

case '9':

nine.start();

break;

case '0':

zero.start();

break;

case '.':

j=resultString.length();

break;

}

}

以上是我的代码,涉及到这个问题。如果有需要的代码等,让我知道。

编辑:

这是做的好方法:

我现在已经得到了它与下面的代码的工作?

private void readAnswer() {

long startTime;

for(int j =0; j

{

int i = resultString.charAt(j);

switch(i) {

case '1':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < one.getDuration()) {

one.start();

}

break;

case '2':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < two.getDuration()) {

two.start();

}

break;

case '3':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < three.getDuration()) {

three.start();

}

break;

case '4':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < four.getDuration()) {

four.start();

}

break;

case '5':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < five.getDuration()) {

five.start();

}

break;

case '6':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < six.getDuration()) {

six.start();

}

break;

case '7':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < seven.getDuration()) {

seven.start();

}

break;

case '8':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < eight.getDuration()) {

eight.start();

}

break;

case '9':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < nine.getDuration()) {

nine.start();

}

break;

case '0':

startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < zero.getDuration()) {

zero.start();

}

break;

case '.':

j=resultString.length();

break;

}

}

}

2017-02-20

benjano

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值