2015-07-02 62 views
1

我似乎無法繞過這個問題。試圖玩音頻文件流服務Xcode 7 - 無法調用AudioFileStreamOpen

一些代碼:

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>)' 

誰能告訴我什麼,我做錯了什麼?

回答

0

我剛碰到這個問題。儘管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 { 
} 
+0

我可以步行通過這個通過Skype /電子郵件/ FB使者。如果你願意的話,也很樂意談論音頻流/迅速。這個組合有很多障礙,只有一個知道與這兩者合作的小社區。你的聯繫信息是什麼? – 3254523