I have an app that plays recorded audio as well as repeating sounds. The sounds play correctly through the onboard iPad speaker, and if I plug in a cord from the earphone jack to my stereo audio-in, it also plays well. When I pair my iPad to my bluetooth stereo input, all the sounds from my other apps (written for iPhone, running on my iPad) work fine, as does all other sound from my device.
The problem is my app written for iPad is NOT playing over the bluetooth path, but instead plays from the built-in speakers.
In my app delegate in the didFinishLaunchingWithOptions(…) method, I have placed the following:
NSError *error = nil;
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeDefault error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&error];
This code is being called and there are no errors being returned.
In my controller code, I have recorded samples that I play using AVAudioPlayer as follows:
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordURL error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer setDelegate:self];
[audioPlayer play];
In other areas, I have drones that are playing short .01 second sounds repeated in a threaded controlled loop and I do this using OpenAL :
alSourcePlay(sourceID);
This is the same code as I have in my other apps written for iPhone that works as desired.
I realize that there are other threads regarding bluetooth input, but I am having a specific issue with bluetooth output of audio sounds from my iPad app.
However, to make things simpler, Apple with iOS 13.2 update has added a new feature called Share Audio and it allows users to listen to the same audio on two different Bluetooth devices at the same time.
It is possible that your device appears to be correctly paired, but yet it has an error. A faulty or weak Bluetooth network often causes this. To resolve this, you will have to unpair the device first. Restart the speaker, then pair the speaker with the Bluetooth device again.
Because your category is Play and Record, you would have to enable Bluetooth as an input in order for it to be supported as an output (by default, the same receiver is used for input/output in Play and Record mode). In order to do that, you would have to set an extra property on your AVAudioSession:
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);
You will also want to check that you didn't force the output to the built in speaker anywhere in your code, by setting the kAudioSessionProperty_OverrideCategoryDefaultToSpeaker
property on your session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With