有没有人通过iOS设备的外部扬声器使用iOS Sprite Kit通过SKAction playSoundFileNamed播放音频有问题?我有以下代码播放M4A文件没有问题通过耳机;但是,当我拔下耳机时,没有播放音频,单步执行没
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ for (UITouch *touch in touches) { CGPoint location = [touch locationInNode:self]; SKAction *sound = [SKAction playSoundFileNamed:@"blast.m4a" waitForCompletion:NO]; [self runAction:sound]; }我有一个类似的问题,但能够通过将AudioSession类别设置为Playback来解决它.这样可以在未插入耳机时通过手机的扬声器传送音频.
// at the top of AppDelegate.m #import <AVFoundation/AVFoundation.h> // in application:didFinishLaunchingWithOptions: NSError *error; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
您可以在Apple的Audio Session Programming Guide中找到更多相关信息.