我正在开发一款使用音频焦点功能播放TextToSpeech的应用。
正常场景 - 播放音乐 - >开始TTS - > TTS获得瞬态焦点 - >完成 - >音乐剧获得焦点。
错误情景 - 播放音乐 - >开始TTS - > TTS获得瞬态焦点 - >接收电话 - > TTS焦点被抛弃 - >通话结束 - >媒体播放器和TTS都可以大量播放焦点。
有没有其他方法来处理这种情况
下面的是Focus侦听器代码
am.requestAudioFocus(afChangeListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request permanent focus.
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
和
回调方法
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
Log.d("READOUT", "Focus AUDIOFOCUS_LOSS_TRANSIENT " + getTTS().isSpeaking() + "SDK version = " + Build.VERSION.SDK_INT);
if (getTTS().isSpeaking()) {
startReadout = true;
stopReading();
}
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN || focusChange == AudioManager.AUDIOFOCUS_GAIN_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) {
Log.d("READOUT", "Focus Gain "+ focusChange);
listnerTTSCallbacks.resumeTTS();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
Log.e("READOUT", "Focus AUDIOFOCUS_LOSS");
stopReading();
}