2012-07-27 106 views
2

去年我的帖子拋出去的機會如何,我看到了我在這個應用程序中掙扎多少。 現在我已經到了最後階段,我真的不明白爲什麼代碼不起作用。我想要做的是將音頻流從手機麥克風路由到sco藍牙耳機。 電話是Samsung Galaxy s2,耳機是Esco Plastronics。 我也跟着在Android網站上的文檔,這是我迄今所做的:在Android中將手機麥克風路由到Sco藍牙耳機

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 &&&&&&&&&",""); 

的permitions在清單文件有:

<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&&&&&&&& 

感謝很多幫助

+0

謝謝@Padma kumar – 2012-08-08 16:13:57

+0

@c v,你是否設法解決這個問題?我面臨同樣的問題,錄製的文件只包含沉默,似乎它試圖抓住藍牙麥克風,但無法達到它。如果它沒有拿到藍牙麥克風,我很驚訝它沒有路由到手機麥克風。 – Harish 2014-02-20 15:47:59

+0

通過使用AM.setBluetoothSco(true),設備將音頻路由到藍牙耳機或從藍牙耳機路由。 – 2014-02-22 08:09:41

回答

2

對周圍AM.setBluetoothScoOn(真),您可能需要調用AM.setMode(MODE_IN_COMMUNICATION);

+1

但這不工作在android lollipop.any解決方法呢? – 2015-04-18 12:55:35

相關問題