使用 AudioManager 后音频流保留在听筒上
在我使用 Android AudioManager 将 SCO 设置为 ON 并打开扬声器后,然后将其返回到开始的位置,媒体流将保留在耳机上而不是手机扬声器上。这是我进行更改以通过 SCO 扬声器路由流的地方(一切都很好)
if (am2.isBluetoothScoAvailableOffCall()) {
am2.startBluetoothSco();
}
if(!am2.isSpeakerphoneOn()){
speakerPhoneWasOn = false;
am2.setSpeakerphoneOn(true);
}
myHash.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
String.valueOf(AudioManager.STREAM_VOICE_CALL));
am2.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
然后我尝试在阅读消息后将其全部更改回来(我正在使用 TTS)
if(SMSstream == 1){
if (am2.isBluetoothScoAvailableOffCall()) {
am2.stopBluetoothSco();
}
if(!speakerPhoneWasOn){
am2.setSpeakerphoneOn(false);
}
}
else{
}
am2.setMode(OLD_AUDIO_MODE);
am2.abandonAudioFocus(null);
但它保留在手机耳机上而不是扬声器,直到我重新启动。我看到一些帖子有相反的问题,但没有一个涉及这个问题。我有一台 Android 2.3.4 的 Droid 3。
您可以在此处查看整个项目和源代码:http://code.google.com/p/a2dpvolume /
After I use the Android AudioManager to set SCO ON and speakerphone ON, then I return it back to where it started, the media stream will then stay on earpiece instead of the phones speaker. Here is where I make the changes to route a stream through the SCO speakerphone (which all works great)
if (am2.isBluetoothScoAvailableOffCall()) {
am2.startBluetoothSco();
}
if(!am2.isSpeakerphoneOn()){
speakerPhoneWasOn = false;
am2.setSpeakerphoneOn(true);
}
myHash.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
String.valueOf(AudioManager.STREAM_VOICE_CALL));
am2.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
Then I try to change it all back after my message is read (I am using TTS)
if(SMSstream == 1){
if (am2.isBluetoothScoAvailableOffCall()) {
am2.stopBluetoothSco();
}
if(!speakerPhoneWasOn){
am2.setSpeakerphoneOn(false);
}
}
else{
}
am2.setMode(OLD_AUDIO_MODE);
am2.abandonAudioFocus(null);
But it stays with the phone earpiece instead of the speaker until I reboot. I saw a few post that had the opposite problem but none with this issue. I have a Droid 3 with Android 2.3.4.
You can see the whole project and source code here: http://code.google.com/p/a2dpvolume/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我终于解决了这个问题。它不漂亮。我相信 AudioManager 中存在某种错误。即使在放弃焦点之后,它也会使设备流变得一团糟。除非在放弃焦点之前通过音乐流读取最后一个 TTS,否则它会错误地路由流、使流静音等。因此,如果之前在除音乐流之外的任何流上读取过 SMS,我只让它读取一个周期放弃焦点。我还清理了我打电话的顺序,并在阅读 TTS 后修复了一些电话模式等。奇怪的是,它似乎运作良好。
OK, I finally fixed this problem. Its not pretty. There is some sort of bug in the AudioManager I believe. Even after abandoning focus it would leave the device streams in a mess. Unless the last TTS was read over the music stream just before abandoning focus, it would route streams wrong, mute streams, etc. So, I just have it read a single period if a SMS had been read over any stream except the music stream before abandoning focus. I also cleaned up the order I called things in, and fixed some of the phone mode, etc after reading a TTS. Strangely it seems to work well.