CFURLRef需要一个桥接施放的错误 [英] CFURLRef requires a bridged cast error
问题描述
我试图让要播放的声音,但是当我code:
I'm trying to get a sound to play but when I code:
AudioServicesCreateSystemSoundID ((CFURLRef) alertSound, &soundFileObject);
这引发以下错误:
it throws the following error:
Objective-C的指针类型'NSURL *'的演员到C指针类型CFURLRef(又名const的结构__CFURL *)需要一个桥接投误差
Cast of Objective-C pointer type 'NSURL *' to C pointer type 'CFURLRef' (aka 'const struct __CFURL *') requires a bridged cast error
我已经试过这两个以下两个建议的解决方案:
I have tried both of the two following suggested solutions:
AudioServicesCreateSystemSoundID ((__bridge CFURLRef) alertSound, &soundFileObject);
或
AudioServicesCreateSystemSoundID ((CFURLRef) CFBridgingRetain(alertSound), &soundFileObject);
但我仍然不能得到的声音播放。
But I still can't get the sound to play.
我想问题是:是桥接错误的声音不玩的原因,或者我应该寻找别的地方
I guess the question is: is the bridging error the cause of the sound not playing, or should I be looking else where?
我能得到声音使用SysSound样本code打,我使用的是iOS 6和X code ++ 4.5。
I can get the sound to play using the SysSound sample code and I'm using iOS 6 and Xcode 4.5.
感谢您的任何指针:)
推荐答案
演员阵容很可能不是声音不玩的原因:
The cast is probably not the reason the sound is not playing:
AudioServicesCreateSystemSoundID ((__bridge CFURLRef) alertSound, &soundFileObject);
是好的。
最有可能你的错误是在你还没有告诉我们code。一个常见的问题是在URL创建或无效的文件格式错误。
Most likely your error is in code that you have not shown us. A common problem is an error in the URL creation or an invalid file format.
修改您的code如下:
Modify your code as follows:
OSStatus status = AudioServicesCreateSystemSoundID((__bridge CFURLRef)alertSound, &soundFileObject);
NSLog(@"AudioServicesCreateSystemSoundID status = %ld", status);
和检查你会得到什么样的地位code; parmErr
(-50)是比较常见的,通常意味着您的网址是零。
and check what status code you get; parmErr
(-50) is relatively common and usually means your URL is nil.
哦,还有更多的思考,你不显示,你实际上是在播放声音。你知道, AudioServicesCreateSystemSoundID
实际上并没有播放声音。你需要调用:
Oh, and one more thought, you don't show where you're actually playing the sound. You do know that AudioServicesCreateSystemSoundID
does not actually play the sound. You need to call:
AudioServicesPlaySystemSound(soundFileObject);
道歉,如果你已经知道了!
Apologies if you knew that already!
这篇关于CFURLRef需要一个桥接施放的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!