将“AudioStreamPacketDescription”的代码转换为swift3.2

Posted

技术标签:

【中文标题】将“AudioStreamPacketDescription”的代码转换为swift3.2【英文标题】:Convert code of "AudioStreamPacketDescription" into swift3.2 【发布时间】:2018-03-10 06:06:51 【问题描述】:

我正在将Audio Queues Service 代码转换为swift3.2,但我卡在这里。我不知道如何在swift 更新版本中编写这行代码。

我想把下面的代码转换成 swift 3.2

player.packetDescs = UnsafeMutablePointer<AudiostreamPacketDescription>(malloc(sizeof(AudioStreamPacketDescription) * Int(player.numPacketsToRead)))

player 对象在哪里:

 class Player 
        var playbackFile: AudioFileID? = nil
        var packetPosition: Int64 = 0
        var numPacketsToRead: UInt32 = 0
        var packetDescs: UnsafeMutablePointer<AudioStreamPacketDescription>? = nil
        var isDone = false
    

我试过这个:

let j = MemoryLayout.size(ofValue: AudioStreamPacketDescription.self) * Int(player.numPacketsToRead)                
player.packetDescs = UnsafeMutablePointer<AudioStreamPacketDescription>(malloc(j))

但这给了我错误:

无法调用类型的初始化程序 带有参数的“UnsafeMutablePointer” '(UnsafeMutableRawPointer!)' 类型列表

【问题讨论】:

【参考方案1】:

好的试试这个

let sizeTmp = MemoryLayout.size(ofValue: AudioStreamPacketDescription.self) * Int(player.numPacketsToRead)
let tmpPointer = UnsafeMutablePointer<AudioStreamPacketDescription>.allocate(capacity: sizeTmp)
player.packetDescs = tmpPointer

【讨论】:

以上是关于将“AudioStreamPacketDescription”的代码转换为swift3.2的主要内容,如果未能解决你的问题,请参考以下文章

如何将Ios文件上传到

Javascript 将正则表达式 \\n 替换为 \n,将 \\t 替换为 \t,将 \\r 替换为 \r 等等

如何将视频文件转换格式

sh 一个将生成CA的脚本,将CA导入到钥匙串中,然后它将创建一个证书并与CA签名,然后将其导入到

python怎么将0写入文件?

如何将CMD窗口背景改成透明?