使用 AudioManager 后音频流保留在听筒上

发布于 2024-12-02 15:36:36 字数 1438 浏览 2 评论 0原文

在我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2024-12-09 15:36:36

好的,我终于解决了这个问题。它不漂亮。我相信 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文