I developed an iPhone application that works as a custom music player. I managed to get a list of all songs in my iPhone into a UITableView. When I play a song, sound comes out of the iPhone audio speakers instead of a Bluetooth-connected device.
In this case, I connected an iPhone to Google Glass via Bluetooth. When a call is received on the iPhone, I can hear the caller through the Google Glass headset. When I play a song in my app, however, audio does not get redirected to the Glass headset. The audio plays through the iPhone's speakers. What I had intended was for the music to play through the Bluetooth-connected device instead,
Please advise me on the proper way to stream audio from a Bluetooth-connected device instead of the phone's speakers.
The code I wrote that should have done this is as follows:
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setDelegate:self];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive: YES error: nil];
// set up for bluetooth microphone input
UInt32 allowBluetoothInput = 1;
OSStatus stat = AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);
NSLog(@"status = %x", (int)stat); // problem if this is not zero
// check the audio route
UInt32 size = sizeof(CFStringRef);
CFStringRef route;
OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route);
NSLog(@"route = %@", route);
NSLog(@"result = %d", (int)result);
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
soundFileURLRef = CFBundleCopyResourceURL (mainBundle,CFSTR ("bomb"),CFSTR ("wav"),NULL);
AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);
AudioServicesPlaySystemSound (soundFileObject);
Thank you in advance for your help!