我正在尝试遍历我的 listView 并突出显示文本视图并播放突出显示的文本。
问题是所有音频文件同时播放,同时突出显示和取消突出显示。并且在播放音频时整个应用程序似乎都在颤抖..
我知道我可能必须使用线程,但仍然不确定如何使用。
这是我的代码
//This is how I call it
Player plOptions = new Player(sound,tf);
plOptions.start();
// this is the thread
private class Player extends Thread
{
String sPlayerPath;
TextView tf;
public Player(String sPath_, TextView tv_) {
sPlayerPath = sPath_;
tf= tv_;
}
@Override
public void run()
{
final MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(sPlayerPath);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
TextHighLight(tf);
}
});
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
TextUnHighLight(tf);
}
});
}
}