我正在開發一個使用第三方tts的應用程序,名爲flite。我正在做一些類似於TTS說句話的事情。我想突出顯示每個單詞。爲此,我設法從tts獲得了字級回調。 工作流程就像這樣 - 按下「發言文本」按鈕。它啓動tt服務,然後將文本發送到C語言的過濾器,並與應用程序結合使用。 現在,從C代碼開始,每個單詞之後我會對兩個不同的java活動進行兩次回調: 一到tts服務說出單詞 秒我的測試java活動突出顯示該單詞。 我成功地在我的測試活動中獲得了單詞級回調,但之後我無法執行任何UI工作。android runonuithread()函數不執行
以下是我在獲取回調時執行的代碼: 這是從C代碼調用的函數。
private void WordCallback(int isword) {// from
// callback
if (isword == -1) {
Log.d(LOG_TAG, "its not a word");
} else if (isword == -2) {
Log.d(LOG_TAG, "yeah..its the end");
} else {
Log.d(LOG_TAG, "its word no " + isword);
int word = isword;
Log.d(LOG_TAG, "highlightwords");
highlightwords(isword);
if (isword == 4) {
Log.d(LOG_TAG, "in if");
new Thread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "thread started");
try {
Flitetest.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "run on ui");
textview.setText("#" + isword);
}
});
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
}
FliteTest是活動的名稱。 日誌打印直到「線程啓動」,但runonuithread()中的代碼永遠不會執行,並且也沒有錯誤。
而且,如果寫不textview.settext("something")
線程和runonuithread(),它給人的錯誤:
fatal signal 11(sigsegv) at 0x6fc64e87(code=1), thread 20292(SynthThread)
。
該行爲的原因是什麼?
好的,你可以請解釋這將如何解決我的問題? –