【问题标题】:Sound issue in Xcode 4.3.2Xcode 4.3.2 中的声音问题
【发布时间】:2012-04-08 07:20:19
【问题描述】:

我更新到 OS X Lion 10.7.3 和 Xcode 4.3.2。我无法使用以下代码在 iPhone 模拟器或 iPhone 设备上播放声音。我可以在 Snow Leopard 和 Xcode 4.2 上使用相同的代码播放声音。我不知道为什么我无法听到 4.3.2 中的声音。有人可以帮忙吗?

.h 文件

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>


@interface soundViewController : UIViewController {
}

-(IBAction)playSounds:(id)sender;

@end

.m 文件

-(IBAction)playSounds:(id)sender {

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"E", CFSTR("caf"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}

【问题讨论】:

  • soundFileURLRef NULL?您是否将E.caf 添加到目标的资源中?
  • 另见similar question
  • 我把 NSError *error NSLog(@"%@", error, userInfo) 和它都返回 null 但在 iMac 上播放 E.caf 在我的目标资源中。
  • 这不是您检查错误的方式。 NSError 不会突然出现,它需要通过某种方法返回。您调用的 CF 或 AudioServices 函数都不会返回 NSError。

标签: iphone ios xcode macos audio


【解决方案1】:

XCode 4.3 有时会无缘无故地从复制资源列表中排除文件。验证该文件是否包含在您的目标中。即使添加它,有时它也不会成为目标的资源。单击文件并选择属性检查器最左侧的选项卡,并确保在“目标成员资格”部分中选中目标旁边的复选框。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    相关资源
    最近更新 更多