简体   繁体   English

SKAction playSoundFileNamed通过iphone扬声器没有音频

[英]SKAction playSoundFileNamed no audio through iphone speaker

Has anyone had issues playing audio via the SKAction playSoundFileNamed using iOS Sprite Kit through the external speaker of your iOS device? 有没有人通过iOS设备的外部扬声器使用iOS Sprite Kit通过SKAction playSoundFileNamed播放音频有问题? I have the following code that plays the M4A file with no issue through the headphones; 我有以下代码播放M4A文件没有问题通过耳机; however, no audio is played when I unplug the headphones stepping through code it executes just no sound. 但是,当我拔下耳机时,没有播放音频,单步执行没有声音的代码。 I have another app that does not use this method and it plays with no issue. 我有另一个不使用此方法的应用程序,它没有问题。

-(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];
 }

I had a similar issue but was able to fix it by setting AudioSession category to Playback. 我有一个类似的问题,但能够通过将AudioSession类别设置为Playback来解决它。 This causes the audio to be routed through the phone's speaker when headphones aren't plugged in. 这样可以在未插入耳机时通过手机的扬声器传送音频。

// at the top of AppDelegate.m
#import <AVFoundation/AVFoundation.h>

// in application:didFinishLaunchingWithOptions:
NSError *error;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

You can find more information about this in Apple's Audio Session Programming Guide . 您可以在Apple的“ 音频会话编程指南”中找到有关此内容的更多信息。

刚刚更新我今天安装了IOS 7.0.4并重新测试,现在我在外部扬声器上有音频,所以我假设它是IOS 7.0.3中的一个错误,因为这是我对设备的唯一改动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM