ios - 核心音频渲染回调中的时间戳可以为空吗?
问题描述
我有一个 iOS 锻炼应用程序,需要在后台保持运行(和播放音频)。可悲的是,据我所知,实现这一点的唯一方法是通过 Core Audio 播放听不见的声音。
一位用户正在经历我无法在模拟器中重现的重复崩溃。(他们有 iPhone 5、iOS 10。)Xcode 中的崩溃报告指出了我以前从未见过崩溃的行。在渲染回调中可以timestamp
为 null 吗?
private func render(ctx: UnsafeMutableRawPointer,
ioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
timeStamp: UnsafePointer<AudioTimeStamp>,
bus: UInt32,
nFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>?) -> OSStatus
{
guard let ioData = ioData else { return noErr }
let abl = UnsafeMutableAudioBufferListPointer(ioData)
guard let bufferData = abl[0].mData else { return noErr }
let impl = Unmanaged<MyClass>.fromOpaque(ctx).takeUnretainedValue()
let buf: UnsafeMutablePointer<Float32> = bufferData.assumingMemoryBound(to: Float32.self)
// **** Crash appears to pointing to this next line.
var t: Int = Int(timeStamp.pointee.mSampleTime) % impl.samples.count
for i in 0..<Int(nFrames) {
buf[i] = impl.samples[t]
t += 1
if t >= impl.samples.count { t = 0 }
}
...
解决方案
推荐阅读
- python - 与 Selenium 作为新的后端开发人员斗争
- batch-file - 存储在批处理字符串中的多行值
- react-native - react-native-chart-kit 问题检查渲染方法
- button - 默认下拉值标题而不是空格
- sql - Oracle:创建会话序列?
- reactjs - 在 React 组件状态中存储大数据
- javascript - 根据断点更改变量
- sql-server - 带有 OPENJSON 的 SQL Server 存储过程:如何确定插入或更新?
- database - 在终端上运行 mongod 命令时 MongoDB 中止
- reactjs - 如何在 reactjs 中设置引导程序以响应?