systemSound不再使用ARC升级的Xcode 4.5.2

时间:2012-11-27 23:30:25

标签: ios xcode

为了播放快速声音,我更喜欢SystemSound而不是AudioPlayer,因为加载时间更快。但现在我升级到Xcode 4.5.2并使用ARC我的代码播放音频片段不再有效。请参阅下面的完整代码我得到的错误来自以下行:AudioServicesCreateSystemSoundID((CFURLRef)filePath,& soundID);我收到红色错误,出现以下错误消息:将目标类型NSURL转换为C指针类型CFURL(又名const dtruct)。任何想法怎么可能取代这一行??`

NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath],   @"/click.mp3"];

SystemSoundID soundID;

NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

// here is the problem line 
     AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);

AudioServicesPlaySystemSound(soundID);

1 个答案:

答案 0 :(得分:1)

使用ARC,您需要在Foundation和Core Foundation之间使用__bridge进行免费桥接。

试试这个:

CFURLRef url = (__bridge CFURLRef)filePath;
AudioServicesCreateSystemSoundID(url, &soundID);
相关问题