Xcode 7 - 无法调用 AudioFileStreamOpen
Posted
技术标签:
【中文标题】Xcode 7 - 无法调用 AudioFileStreamOpen【英文标题】:Xcode 7 - Can't call AudioFileStreamOpen 【发布时间】:2015-07-02 18:44:14 【问题描述】:我似乎无法解决这个问题。尝试使用音频文件流服务。
一些代码:
import Foundation
import AudioToolbox
public class StreamingPlayback
var audioFileStream: UnsafeMutablePointer<AudioFileStreamID>?
var inClientData: UnsafeMutablePointer<Void> = nil
init()
func start ()
AudioFileStreamOpen(&inClientData, propertyProc, packetProc, kAudioFileMP3Type, &audioFileStream)
func propertyProc(inClientData: UnsafeMutablePointer<()>,inFileStreamId: AudioFileStreamID,inPropertyId: AudioFileStreamPropertyID,ioFlags: UnsafeMutablePointer<UInt32>) -> Void
func packetProc(inClientData: UnsafeMutablePointer<()>,inNumberOfBytes: UInt32,inNumberOfPackets: UInt32, UnsafeMutablePointer<()>, inPacketDescriptions: UnsafePointer<AudiostreamPacketDescription>) -> Void
这给了我:
Cannot invoke 'AudioFileStreamOpen' with an argument list of type '(inout UnsafeMutablePointer<Void>, (UnsafeMutablePointer<()>, inFileStreamId: AudioFileStreamID, inPropertyId: AudioFileStreamPropertyID, ioFlags: UnsafeMutablePointer<UInt32>) -> Void, (UnsafeMutablePointer<()>, inNumberOfBytes: UInt32, inNumberOfPackets: UInt32, UnsafeMutablePointer<()>, inPacketDescriptions: UnsafePointer<AudioStreamPacketDescription>) -> Void, AudioFileTypeID, inout UnsafeMutablePointer<AudioFileStreamID>?)'
Expected an argument list of type '(UnsafeMutablePointer<Void>, AudioFileStream_PropertyListenerProc, AudioFileStream_PacketsProc, AudioFileTypeID, UnsafeMutablePointer<AudioFileStreamID>)'
谁能告诉我我做错了什么?
【问题讨论】:
【参考方案1】:我刚刚遇到了这个问题。尽管 Swift 2.0 支持 c 函数回调,但仍然存在一些问题。我确实找到了解决方法。试试这个:
@objc protocol HandleAudioPacketsDelegate
func handlePacketsProc(ioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp: UnsafePointer<AudioTimeStamp>,
inBufNumber: UInt32,
inNumberFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>) -> OSStatus
func packetsProc(inRefCon: UnsafeMutablePointer<Void>,
ioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp: UnsafePointer<AudioTimeStamp>,
inBufNumber: UInt32,
inNumberFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>)
-> OSStatus
let delegate = unsafeBitCast(inRefCon, HandleAudioPacketsDelegate.self)
let result = delegate.handlePacketsProc(ioActionFlags,
inTimeStamp: inTimeStamp,
inBufNumber: inBufNumber,
inNumberFrames: inNumberFrames,
ioData: ioData)
return result
然后在您的StreamingPlayback
类中使用此方法进行回调:
func handlePacketsProcioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp: UnsafePointer<AudioTimeStamp>,
inBufNumber: UInt32,
inNumberFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>) -> OSStatus
【讨论】:
我可以通过 skype/email/fb messenger 引导您完成此操作。如果您愿意,也很乐意谈论音频流/swift。这个组合有很多障碍,只有一个小社区知道如何与这两者合作。你的联系方式是什么?以上是关于Xcode 7 - 无法调用 AudioFileStreamOpen的主要内容,如果未能解决你的问题,请参考以下文章
由于“链接器命令失败,退出代码为 1(使用 -v 查看调用)”,无法在 El Capitan 上为 Xcode 7 项目构建开发分支