音频流使用AudioManager后停留在听筒 [英] Audio stream stays on earpiece after using AudioManager

查看:224
本文介绍了音频流使用AudioManager后停留在听筒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Android AudioManager设置SCO ON和扬声器ON后,然后我回到它回到它开始,媒体流会再留在听筒,而不是手机的扬声器。这里是我做的,通过扬声器SCO流(所有的伟大工程)更改路线

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);

然后我试图改变这一切回来读我的消息后(我使用TTS)

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);

但它保持与手机听筒,而不是直到我重新启动扬声器。我看了几个帖子说了相反的问题,但这个问题没有。我有一个Droid 3的与Android 2.3.4。

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.

您可以在这里看到整个项目和源$ C ​​$ C:的http:// code.google.com / p / a2dpvolume /

You can see the whole project and source code here: http://code.google.com/p/a2dpvolume/

推荐答案

OK,我终于解决了这个问题。它不是pretty。有一个在AudioManager我相信有些类型的错误。即使放弃焦点后会离开该装置中的流得一塌糊涂。除非最后TTS刚刚放弃的焦点之前阅读过的音乐流,它会流路线错误,静音流,等等。所以,我只是把它读一个单一的时期,如果短信已经阅读过任何流,除了之前的音乐流放弃焦点。我还清理了我叫事物的秩序,并读取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.

这篇关于音频流使用AudioManager后停留在听筒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆