How to use the CoreAudio API in Swift

后端 未结 2 1111
无人及你
无人及你 2020-12-10 22:01

I am in the process of migrating my streaming audio engine to swift. i am finding it difficult to use the C Audio API in swift.

I have a problem with AudioFileStream

2条回答
  •  [愿得一人]
    2020-12-10 22:37

    I don't know much about Audio API, however, you should replace UnsafePointer by a pointer to an Object. for example:

    var clientData : AnyObject?
    var listenerProc : AudioFileStream_PropertyListenerProc = AudioFileStream_PropertyListenerProc.convertFromNilLiteral()
    var packetsProc : AudioFileStream_PacketsProc = AudioFileStream_PacketsProc.convertFromNilLiteral()
    var audioFileTypyeId : AudioFileTypeID = 0
    
    AudioFileStreamOpen(&clientData, listenerProc, packetsProc, audioFileTypyeId, &streamId)
    

    the initialization code for listenerProc, packetsProc or other variables is just to by-pass the compiler error.

    To your situation, try to replace 'self as UnsafePointer<>' by '&self'. However 'self' must be something that can be converted to compatible data type.

    https://developer.apple.com/library/prerelease/ios/documentation/MusicAudio/Reference/AudioStreamReference/index.html#//apple_ref/c/func/AudioFileStreamOpen

提交回复
热议问题