ios - AudioServicesCreateSystemSoundID 和内存地址参数 - 如何传递属性?

标签 ios objective-c audio

我有一个方法 AudioServicesCreateSystemSoundID,根据文档,该方法似乎需要传入内存地址(*outSystemSoundID)。

来自 Apple 的网站...

OSStatus AudioServicesCreateSystemSoundID (
   CFURLRef       inFileURL,
   SystemSoundID  *outSystemSoundID
);

当我在方法中创建本地对象时,我有这段代码可以工作。该对象已正确分配到内存位置。

这将返回 myTest ,代码为:0(这就是我想要的)

 SystemSoundID thisSoundID;

 SystemSoundID myTest = AudioServicesCreateSystemSoundID
 (
 (__bridge CFURLRef)(url), &thisSoundID
 );

但这就是我想要做的。 (我已将 self.theSound 设置为 SystemSoundID 属性)。

这将返回 myTest 并带有错误代码:4294967246(我不想要这个)

SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
    (__bridge CFURLRef)(url), self.theSound
);

最佳答案

编译器将 self.theSound 翻译为

[self theSound]

其中 -(SystemSoundID)theSound 是(自动合成的)getter 方法 您的属性(默认情况下)从 _theSound 实例获取值 变量。

所以你不能将“属性的地址”传递给函数。 您可以改为传递实例变量的地址:

SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
    (__bridge CFURLRef)(url), &self->_theSound
);

绕过属性访问器。但我建议使用临时的 变量代替:

 SystemSoundID thisSoundID;
 SystemSoundID myTest = AudioServicesCreateSystemSoundID
 (
     (__bridge CFURLRef)(url), &thisSoundID
 );
 self.theSound = thisSoundID;

关于ios - AudioServicesCreateSystemSoundID 和内存地址参数 - 如何传递属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21388175/

相关文章:

ios - GPUImage 相机需要五秒钟

ios - 为什么 AVPlayer 不停止加载数据?

ios - Objective-C 中的常量和 "duplicate symbol"链接器错误

objective-c - 在 Objective-C 中,你在哪里声明一个常量?

objective-c - 12 小时模式的 NSDateFormatter

ios - 在 iOS 上从 RIFF 容器读取 AAC 音频

ios - AVAudioRecorderDelegate 的代表没有调用

ios - 使用 NSDictionary Objective C(用于登录)检查 TextField 中的值

c++ - 音频关闭时线程很慢

iphone - iOS 6 : Turn off keyboard shortcuts