Objective c 如何在蓝牙连接的设备上播放歌曲(在Objective C中开发的应用程序)
我开发了一个iPhone应用程序,可以作为自定义音乐播放器使用。我设法将iPhone中所有歌曲的列表放入UITableView。当我播放歌曲时,声音来自iPhone音频扬声器,而不是蓝牙连接设备 在本例中,我通过蓝牙将iPhone连接到谷歌眼镜。当iPhone收到来电时,我可以通过谷歌眼镜耳机听到来电者的声音。但是,当我在应用程序中播放歌曲时,音频不会重定向到玻璃耳机。音频通过iPhone的扬声器播放。我原本打算通过蓝牙连接的设备播放音乐 请告诉我从蓝牙连接设备而不是手机扬声器传输音频的正确方法 我编写的代码应该这样做,如下所示:Objective c 如何在蓝牙连接的设备上播放歌曲(在Objective C中开发的应用程序),objective-c,iphone,audio,bluetooth,google-glass,Objective C,Iphone,Audio,Bluetooth,Google Glass,我开发了一个iPhone应用程序,可以作为自定义音乐播放器使用。我设法将iPhone中所有歌曲的列表放入UITableView。当我播放歌曲时,声音来自iPhone音频扬声器,而不是蓝牙连接设备 在本例中,我通过蓝牙将iPhone连接到谷歌眼镜。当iPhone收到来电时,我可以通过谷歌眼镜耳机听到来电者的声音。但是,当我在应用程序中播放歌曲时,音频不会重定向到玻璃耳机。音频通过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蓝牙模式,因此不能用作音乐的通用蓝牙耳机 感谢您的回复。如果有其他方式,iPhone音频将重定向到谷歌眼镜。请告诉我一些想法