我是android开发的新手。我正在制作一个基于听写的应用程序。
在下面的活动中,我有 15 个小音频片段;文件一个接一个地播放,延迟 5 秒。
我的问题是我如何才能只播放 15 个片段中的 10 个片段?我还希望随机播放 10 个剪辑。
任何帮助将不胜感激。
package com.example.dictationary;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Level1 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.level1);
MediaPlayer n1 = MediaPlayer.create(this,R.raw.assassin);
final MediaPlayer n2 = MediaPlayer.create(this,R.raw.accessible);
final MediaPlayer n3 = MediaPlayer.create(this,R.raw.bashfully);
final MediaPlayer n4 = MediaPlayer.create(this,R.raw.blistering);
final MediaPlayer n5 = MediaPlayer.create(this,R.raw.butter);
final MediaPlayer n6 = MediaPlayer.create(this,R.raw.campaign);
final MediaPlayer n7 = MediaPlayer.create(this,R.raw.circumstances);
final MediaPlayer n8 = MediaPlayer.create(this,R.raw.clinching);
final MediaPlayer n9 = MediaPlayer.create(this,R.raw.deferential);
final MediaPlayer n10 = MediaPlayer.create(this,R.raw.distinguished);
final MediaPlayer n11 = MediaPlayer.create(this,R.raw.embarrass);
final MediaPlayer n12 = MediaPlayer.create(this,R.raw.etiquette);
final MediaPlayer n13 = MediaPlayer.create(this,R.raw.fatigue);
final MediaPlayer n14 = MediaPlayer.create(this,R.raw.feasible);
final MediaPlayer n15 = MediaPlayer.create(this,R.raw.glitch);
n1.start();
Timer buttonTimer = new Timer();
buttonTimer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n2.start();
}
});
}
}, 5000);
Timer buttonTimer1 = new Timer();
buttonTimer1.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n3.start();
}
});
}
}, 10000);
Timer buttonTimer2 = new Timer();
buttonTimer2.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n4.start();
}
});
}
}, 15000);
Timer buttonTimer3 = new Timer();
buttonTimer3.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n5.start();
}
});
}
}, 20000);
Timer buttonTimer4 = new Timer();
buttonTimer4.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n6.start();
}
});
}
}, 25000);
Timer buttonTimer5 = new Timer();
buttonTimer5.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n7.start();
}
});
}
}, 30000);
Timer buttonTimer6 = new Timer();
buttonTimer6.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n8.start();
}
});
}
}, 35000);
Timer buttonTimer7 = new Timer();
buttonTimer7.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n9.start();
}
});
}
}, 40000);
Timer buttonTimer8 = new Timer();
buttonTimer8.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n10.start();
}
});
}
}, 45000);
Timer buttonTimer9 = new Timer();
buttonTimer9.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n11.start();
}
});
}
}, 50000);
Timer buttonTimer10 = new Timer();
buttonTimer10.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n12.start();
}
});
}
}, 55000);
Timer buttonTimer11 = new Timer();
buttonTimer11.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n13.start();
}
});
}
}, 60000);
Timer buttonTimer12 = new Timer();
buttonTimer12.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n14.start();
}
});
}
}, 65000);
Timer buttonTimer13 = new Timer();
buttonTimer13.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
n15.start();
}
});
}
}, 70000);
}
}