Search code examples
androidandroid-bluetoothandroid-audiomanagerandroid-audiorecord

Audio track not working through Bluetooth in Samsung S6


I am recording audio using AudioRecord and playing using AudioTrack. I am recording Fm analog audio stream using this classes and simultaneously passing into Bluetooth router. Its successfully working with Motorola and Samsung S5. But not working with Samsung Galaxy S6.

This is the sample code how i am recording

                            audioManager.startBluetoothSco();
                            audioManager.setBluetoothScoOn(true);
                            audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

                       //FM_SRC is the FM receiving Antenna
                        mRecorder = new AudioRecord(FM_SRC, sampleRateInHz,
                                channelConfigIn,
                                AudioFormat.ENCODING_PCM_16BIT,
                                bufferSizeInBytes);

                        mAudioTrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                                sampleRateInHz, channelConfigOut,
                                AudioFormat.ENCODING_PCM_16BIT,
                                bufferSizeInBytes,
                                AudioTrack.MODE_STREAM);


                                mRecorder.startRecording();
                                mAudioTrack.play();

                            byte data[] = new byte[bufferSizeInBytes];

                            //Shuffling buffers from record to track object until A2DP routing selected
                            while (mOverA2DP) {
                                // Log.e(TAG, "mOverA2DP:" + mOverA2DP);
                                mRecorder.read(data, 0, bufferSizeInBytes);
                                mAudioTrack.write(data, 0, bufferSizeInBytes);
                            }

Please help me.


Solution

  • Including the Android OS versions in your question might be helpful. I've encountered issues with Bluetooth in 4.4 which were are present in 4.1 or 5.0.

    The specific problem I've seen is a bluetooth disconnect after a short period of time with Android 4.4. Commands from my headset to my app stopped working a couple of minutes after launching the app. It's not exactly your problem, but it might help you troubleshoot.

    (I would have made this a comment but I don't have the reputation to comment yet).