下面的条件下停止正在运行的线程,当用户单击某个拼写按钮时,它会播放音频以显示每个字母来读出一个单词的字母。它成功实施!如何在Android应用程序的ANDROID
而我用滑动手势来改变这个词。如果用户滑动屏幕,则应该显示另一个单词。并且它也成功实施了!
问题:
而如果用户刷那么音频应停止并应和显示下一个单词(我猜正在运行的线程应该停止)音频播放。
我该怎么做?任何方案?
代码概述:
public class BirdsActivity extends Activity implements OnClickListener{
//On createMethod*(){
.
.
//on Spell button click run a thread to play audio and draw text
new DrawLetter("AlphaKids").start();
// initiate Gesture detection
}
class DrawLetter extends Thread {
String tempName=names[position];
String b="";
int i=0;
public DrawLetter(String str) {
super(str);
}
public void run() {
for (int i = 0; i < names[position].length(); i++) {
runOnUiThread(new Runnable()
{
public void run()
{ txtFrontName.setText(b); }
});
mPlayVoice = MediaPlayer.create(BirdsActivity.this, mAlphabetsSound[letterPosition]);
mPlayVoice.start();
try {
sleep(500);
mPlayVoice.release();
} catch (InterruptedException e) {}
}}
.
.
.
// Gesture detection class
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//if valid swipe is performed
{
//i want to stop(or Distroy) the above thread here
}
} }
抱歉.. mPlayVoice.stop()停止mediya的球员,但同时线程再次运行时它开始 – vnshetty
我不太明白你的代码。为什么MediaPlayer会在你的线程的循环中开始?你在播放多个文件吗?考虑更新你的问题,使其更清楚。 –
ok ....在UI线程内初始化你的mPlayVoice,而不是初始化成新线程的run方法。像mPlayVoice = MediaPlayer.create(BirdsActivity.this,mAlphabetsSound [letterPosition]);在UIThread中执行此操作。我的意思是在你的runOnUIThread Line之上的代码中。 ..我想它现在应该可以解决你的问题 –