我开发了一个iPhone应用程序,可以用作自定义音乐播放器。我设法将iPhone中所有歌曲的列表放入用户界面视图中。当我播放歌曲时,声音从 iPhone 音频扬声器而不是蓝牙连接设备发出。
在这种情况下,我通过蓝牙将iPhone连接到谷歌眼镜。当iPhone上收到来电时,我可以通过谷歌眼镜耳机听到来电。然而,当我在应用程序中播放歌曲时,音频不会重定向到Glass耳机。音频通过iPhone的扬声器播放。我原本打算通过蓝牙连接设备播放音乐,
请告诉我从蓝牙连接设备而不是手机扬声器传输音频的正确方法。
我编写的应该完成此任务的代码如下:
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);
提前感谢您的帮助!
目前Glass不能用作音乐的通用蓝牙耳机,因为它不支持A2DP蓝牙配置文件。