2

去年我的帖子中的这些机会如何让我看到了我在这个应用程序上的挣扎。现在我已经到了最后阶段,我真的不明白为什么代码不起作用。我想要做的是将音频流从电话麦克风路由到 sco 蓝牙耳机。手机是三星 Galaxy s2,耳机是 Esco Plastronics。我遵循了 android 网站上的文档,这就是我到目前为止所做的:

tools.Log("&&&&&&&& debug &&&&&&&&&","");
tools.Log("&&&&&&&& debug &&&&&&&&&","");
tools.Log("&&&&&&&& debug &&&&&&&&&","");
tools.Log("FBR.SetUpAudioRecoder", "In");
public static final int SAMPPERSER =  8000;
public int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
public int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
public AudioManager AM = (AudioManager) mcontext.getSystemService(Context.AUDIO_SERVICE);

buffersizebytes = AudioRecord.getMinBufferSize(SAMPPERSEC,channelConfiguration, audioEncoding);     buffersizebytes = (short) (buffersizebytes * 20);
audioRecord = new AudioRecord(
      android.media.MediaRecorder.AudioSource.MIC,SAMPPERSEC,channelConfiguration,audioEncoding,buffersizeb   ytes); // constructor
//Debug
boolean tmp = AM.isBluetoothScoAvailableOffCall();//Returns true
tools.Log("AM.isBluetoothScoAvailableOffCall() is -",tools.BoolToString(tmp));
try {
    audioRecord.startRecording();
} catch (IllegalStateException e) {
    tools.Log("FBR.GetAudioFromMic:startRecording:Error ",
                e.getMessage());
    return "Get Audio From Mic Error";
}
AM.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
AM.setBluetoothScoOn(true);
AM.startBluetoothSco();// HERE I GET A BEEP ON THE HEADSET
tmp = AM.isBluetoothScoOn();// Returns true
tools.Log("AM.isBluetoothScoOn() is - ",    tools.BoolToString(tmp));
tools.Log("&&&&&&&& end debug &&&&&&&&&","");
tools.Log("&&&&&&&& end debug &&&&&&&&&","");
tools.Log("&&&&&&&& end debug &&&&&&&&&","");

清单文件上的许可是:

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>

日志给了我很多我无法理解的信息,所以我只附上了几行。

20 08:56:02.090:D/SpySitter(9659): &&&&&&&&& debug &&&&&&&&&&-
01-20 08:56:02.090: D/SpySitter(9659): FBR.SetUpAudioRecoder-In

01-20 08:56:02.100: I/AudioHardwareYamaha(1833): getInputBufferSize() rate 8000, size 512 

01-20 08:56:02.110: I/AudioPolicyManager(1833): getDeviceForInputSource()input source 1, device 00100000

01-20 08:56:02.110: I/AudioHardwareYamaha(1833): AudioStreamIn::set(1, 16, 8000)

01-20 08:56:02.110: I/AudioHardwareYamaha(1833): bufferSize() channels 2, bufferRatio 4, size 1024

01-20 08:56:02.115: I/AudioHardwareYamaha(1833): AudioStreamIn::standby()

01-20 08:56:02.120: D/SpySitter(9659): AM.isBluetoothScoAvailableOffCall() is - -true

01-20 08:56:02.125: I/AudioService(1989): isMediaSilentMode false

20 08:56:02.140: I/AudioPolicyManager(1833): getDeviceForStrategy() strategy 4, device 2

01-20 08:56:02.145: I/AudioPolicyManager(1833): setForceUse() usage 2, config 3, mPhoneState 0

01-20 08:56:03.475: E/DataRouter(1828): usb connection is true 

01-20 08:56:03.475: E/DataRouter(1828): DSR is ON. Don't send DTR ON

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): initiateScoUsingVirtualVoiceCall: Received

01-20 08:56:05.010: V/Bluetooth AT sent(2240): +CIEV: 3,2

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): initiateScoUsingVirtualVoiceCall: Sent Call-setup 
procedure

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): audioOn()

01-20 08:56:05.010: D/Bluetooth HS/HF(2240): setAudioState(11)

01-20 08:56:05.015: D/Bluetooth HSHFP(2240): AudioStateIntent:  State: 11 PrevState: 10

01-20 08:56:05.015: V/BluetoothSocket.cpp(2240): initSocketNative

01-20 08:56:05.015: V/BluetoothSocket.cpp(2240): ...fd 99 created (SCO, lm = 0)

01-20 08:56:05.015: V/BluetoothSocket.cpp(2240): initSocketFromFdNative

01-20 08:56:05.040: D/Bluetooth HS/HF(2240): initiateScoUsingVirtualVoiceCall: Done

01-20 08:56:05.045: I/BluetoothPolicyService(1989): isPairingEnabled 

01-20 08:56:05.055: D/BluetoothUtils(2240): isSocketAllowedBySecurityPolicy start : device null

01-20 08:56:05.055: V/BluetoothSocket.cpp(2240): connectNative

01-20 08:56:05.065: V/Bluetooth AT recv(2240): AT+CLCC

01-20 08:56:05.070: V/Bluetooth AT sent(2240): +CLCC: 1,0

01-20 08:56:05.080: V/BluetoothSocket.cpp(2240): ...connect(99, SCO) = 0 (errno 115)

01-20 08:56:05.080: D/Bluetooth HS/HF(2240): Routing audio for outgoing SCO conection

01-20 08:56:16.455: D/SpySitter(9659): &&&&&&&&&&&& end debug&&&&&&&&

非常感谢您的帮助

4

1 回答 1

2

在 AM.setBluetoothScoOn(true) 附近,您可能需要调用 AM.setMode(MODE_IN_COMMUNICATION);

于 2013-12-12T16:25:49.320 回答