swift - Swift 中的 AURenderCallbackStruct

标签 swift callback

我有一个 AURenderCallbackStruct 的 Objective-C 示例,我想快速完成一个。我读到这是不可能的,对吗?

谢谢。

最佳答案

您可以像下面这样在 Swift 4 中格式化回调函数。

func recordingCallback(
  inRefCon:UnsafeMutableRawPointer,
  ioActionFlags:UnsafeMutablePointer<AudioUnitRenderActionFlags>,
  inTimeStamp:UnsafePointer<AudioTimeStamp>,
  inBusNumber:UInt32,
  inNumberFrames:UInt32,
  ioData:UnsafeMutablePointer<AudioBufferList>?) -> OSStatus {


  return noErr
}

请注意,这必须是一个全局函数并且在一个类中。

然后您可以使用以下代码设置回调函数:

var callbackStruct = AURenderCallbackStruct()
callbackStruct.inputProc = recordingCallback
callbackStruct.inputProcRefCon = nil
status = AudioUnitSetProperty(remoteIOUnit!,
                                  kAudioOutputUnitProperty_SetInputCallback,
                                  kAudioUnitScope_Global,
                                  bus1,
                                  &callbackStruct,
                                  UInt32(MemoryLayout<AURenderCallbackStruct>.size));
if (status != noErr) {
  return status // Do something with the error
}

Source

关于swift - Swift 中的 AURenderCallbackStruct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29942310/

相关文章:

ios - 显示 UIPopOverPresentationController 时崩溃

ios - 无法调用非函数类型的值 "UIViewController?"

ios - 访问前一个 viewController 元素及其标签

java - RMI、EJB 和回调

ios - 使用 UIPanGestureRecognizer 更新约束

java - Android - 适配器数据更改后,滚动到 ListFragment 中 ListView 中的位置

javascript - 将一个有点复杂的 javascript 函数的值返回给 silverlight 用户控件

javascript - 访问请求cheerios函数外部的变量

javascript - JS中命名回调函数和匿名回调函数的区别

swift - 在照片项目扩展中显示选定的照片