1
我試圖通過文本語音轉換系統說出短語時使音頻播放器無聲。正如預期的那樣,音頻管理器會在請求音頻焦點時減小音量,但在放棄AudioFocus時,音量不會恢復,並且不會調用abandonAudioFocus的回調。 這是我的代碼:Audiomanager.abandonAudioFocus不會繼續播放
private class SpeakRunnable implements Runnable {
String mText;
public SpeakRunnable(String text) {
mText = text;
}
@Override
public void run() {
stream_volume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
am.requestAudioFocus(new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
//Check if focus granted
.....
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "none");
talker.speak(mText, TextToSpeech.QUEUE_ADD, params);
}
},
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
}
}
和:
talker.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
}
@Override
public void onError(String utteranceId) {
}
@Override
public void onDone(String utteranceId) {
am.abandonAudioFocus(new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
Log.v(app_id, "CALLBACK");
}
});
}
});
任何想法?提前致謝。
你說得對。那是我的錯誤。 謝謝! – dantard 2014-10-28 14:11:44