Question

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.

Était-ce utile?

La solution 3

Not possible.

From the very interesting Apple doc AVAudioSession -- Selecting a microphone QA1799:

If an application uses the setPreferredInput:error: method to select a Bluetooth HFP input, the output will automatically be changed to the Bluetooth HFP output. Moreover, selecting a Bluetooth HFP output using the MPVolumeView's route picker will automatically change the input to the Bluetooth HFP input. Therefore both the input and output will always end up on the Bluetooth HFP device even though only the input or output was set individually.

Autres conseils

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.

this is the solution at the moment, but is deprecated and anyone know the new solution, but add this part of code on your app now and all working very well!!

 UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Hope this help you!

Did you check with setCategory withOptions? Its start from iOS 6

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&error];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top