- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 iOS 9/10 和 iOS 11 之间看到了不同的行为,当发生音频路由更改时(例如,您插入耳机)在 AVAudioPlayerNode 上安排 future 的缓冲区。有没有人遇到过类似的事情,你是如何解决的?请注意,我大约两周前在 Apple 的 AVFoundation 支持论坛上报告了这个问题,但收到的回复完全为零。
显示此问题的代码如下所示 - 首先简要说明:该代码是一个简单的循环,它重复安排缓冲区在将来的某个时间播放。该过程通过调用“runSequence”方法开始,该方法安排音频缓冲区在 future 某个时间播放,并将完成回调设置为嵌套方法“audioCompleteHandler”。完成回调再次调用“runSequence”方法,该方法调度另一个缓冲区并使进程永远运行。在这种情况下,除非完成处理程序正在执行,否则总是有一个缓冲区被调度。各个地方的“trace”方法是内部打印方法,仅在调试时进行打印,因此可以忽略。
在音频路由更改通知处理程序 (handleAudioRouteChange) 中,当新设备可用时(case .newDeviceAvailable),代码会重新启动引擎和播放器,重新激活 Audio Session 并调用“runSequence”以将循环重新启动。
这一切在 iOS 9.3.5 (iPhone 5C) 和 iOS 10.3.3 (iPhone 6) 上运行良好,但在 iOS 11.1.1 (iPad Air) 上失败。失败的本质是 AVAudioPlayerNode 不播放音频而是立即调用完成处理程序。这会导致失控的情况。如果我再次删除启动循环的行(如代码所示),它在 iOS 11.1.1 上运行良好,但在 iOS 9.3.5 和 iOS 10.3.3 上失败。这个失败是不同的:音频刚刚停止,在调试器中,我可以看到循环没有循环。
所以,一个可能的解释是,在 iOS 9.x 和 iOS 10.x 下,当音频路由发生变化时, future 的预定缓冲区是未预定的,而在 iOS 11.x 下, future 预定的缓冲区不是未预定的。
这导致两个问题:
1. 有没有人看到过类似的行为,解决方法是什么?
2. 任何人都可以向我指出在音频路由更改(或音频中断)发生时描述引擎、播放器和 session 的确切状态的文档吗?
private func runSequence() {
// For test ony
var timeBaseInfo = mach_timebase_info_data_t()
mach_timebase_info(&timeBaseInfo)
// End for test only
let audioCompleteHandler = { [unowned self] in
DispatchQueue.main.async {
trace(level: .skim, items: "Player: \(self.player1.isPlaying), Engine: \(self.engine.isRunning)")
self.player1.stop()
switch self.runStatus {
case .Run:
self.runSequence()
case .Restart:
self.runStatus = .Run
self.tickSeq.resetSequence()
//self.updateRenderHostTime()
self.runSequence()
case .Halt:
self.stopEngine()
self.player1.stop()
self.activateAudioSession(activate: false)
}
}
}
// Schedule buffer...
if self.engine.isRunning {
if let thisElem: (buffer: AVAudioPCMBuffer, duration: Int) = tickSeq.next() {
self.player1.scheduleBuffer(thisElem.buffer, at: nil, options: [], completionHandler: audioCompleteHandler)
self.player1.prepare(withFrameCount: thisElem.buffer.frameLength)
self.player1.play(at: AVAudioTime(hostTime: self.startHostTime))
self.startHostTime += AVAudioTime.hostTime(forSeconds: TimeInterval(Double(60.0 / Double(self.model.bpm.value)) * Double(thisElem.duration)))
trace(level: .skim, items:
"Samples: \(thisElem.buffer.frameLength)",
"Time: \(mach_absolute_time() * (UInt64(timeBaseInfo.numer) / UInt64(timeBaseInfo.denom))) ",
"Sample Time: \(player1.lastRenderTime!.hostTime)",
"Play At: \(self.startHostTime) ",
"Player: \(self.player1.isPlaying)",
"Engine: \(self.engine.isRunning)")
}
else {
}
}
}
@objc func handleAudioRouteChange(_ notification: Notification) {
trace(level: .skim, items: "Route change: Player: \(self.player1.isPlaying) Engine: \(self.engine.isRunning)")
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else { return }
trace(level: .skim, items: audioSession.currentRoute, audioSession.mode)
trace(level: .none, items: "Reason Value: \(String(describing: userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt)); Reason: \(String(describing: AVAudioSessionRouteChangeReason(rawValue:reasonValue)))")
switch reason {
case .newDeviceAvailable:
trace(level: .skim, items: "In handleAudioRouteChange.newDeviceAvailable")
for output in audioSession.currentRoute.outputs where output.portType == AVAudioSessionPortHeadphones {
startEngine()
player1.play()
activateAudioSession(activate: true)
//updateRenderHostTime()
runSequence() // <<--- Problem: works for iOS9,10; fails on iOS11. Remove it and iOS9,10 fail, works on iOS11
}
case .oldDeviceUnavailable:
trace(level: .skim, items: "In handleAudioRouteChange.oldDeviceUnavailable")
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription {
for output in previousRoute.outputs where output.portType == AVAudioSessionPortHeadphones {
player1.stop()
stopEngine()
tickSeq.resetSequence()
DispatchQueue.main.async {
if let pp = self.playPause as UIButton? { pp.isSelected = false }
}
}
}
最佳答案
因此,通过进一步挖掘/测试解决了问题:
@objc func handleAudioRouteChange(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue:reasonValue) else { return }
switch reason {
case .newDeviceAvailable:
for output in audioSession.currentRoute.outputs where output.portType == AVAudioSessionPortHeadphones {
headphonesConnected = true
}
startEngine() // Do this regardless of whether engine.isRunning == true
if let lrt = player.lastRenderTime, let st = player.playerTime(forNodeTime: lrt)?.sampleTime {
playSampleOffset += st // Accumulate so that multiple inserts/removals move the play point forward
stopPlayer()
scheduleSegment(file: playFile, at: nil, player: player, start: playSampleOffset, length: AVAudioFrameCount(playFile.length - playSampleOffset))
startPlayer()
}
else {
// Unknown problem with getting sampleTime; reset engine, player(s), restart as appropriate
}
case .oldDeviceUnavailable:
if let previousRoute =
userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription {
for output in previousRoute.outputs where output.portType == AVAudioSessionPortHeadphones {
headphonesConnected = false
}
}
startEngine() // Do this regardless of whether engine.isRunning == true
if let lrt = player.lastRenderTime, let st = player.playerTime(forNodeTime: lrt)?.sampleTime {
playSampleOffset += st // Accumulate...
stopPlayer()
scheduleSegment(file: playFile, at: nil, player: player, start: playSampleOffset, length: AVAudioFrameCount(playFile.length - playSampleOffset))
startPlayer() // Test only, in reality don't restart here; set play control to allow user to start audio
}
else {
// Unknown problem with getting sampleTime; reset engine, player(s), restart as appropriate
}
关于ios11 - AVAudioPlayerNode 调度缓冲区和 iOS11 中的音频路由更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47567882/
我有一个功能是转换 ADO Recordset 进入html: class function RecordsetToHtml(const rs: _Recordset): WideString; 该函
经过几天的研究和讨论,我想出了这种方法来收集访客的熵(你可以看到我的研究历史here) 当用户访问时,我运行此代码: $entropy=sha1(microtime().$pepper.$_SERVE
给定一个无序列表 List ,我需要查找是否存在 String与提供的字符串匹配。 所以,我循环 for (String k : keys) { if (Utils.keysM
我已经搜索过这个问题,但没有找到我正在寻找的答案。 基本上,我想将类构造函数包装在 try/except 子句中,以便它忽略构造函数内特定类型的错误(但无论如何都会记录并打印它们)。我发现做到这一点的
我有一组三个数字,我想将一组数字与另一组数字进行比较。即,第一组中的每个数字小于另一组中的至少一个数字。需要注意的是,第一组中的下一个数字必须小于第二组中的不同数字(即,{6,1,6} 对 {8,8,
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
首先介绍一下背景: 我正在开发一个带有 EJB 模块和应用程序客户端模块的企业应用程序 (ear)。我还使用 hibernate JPA 来实现持久性,并使用 swingx 来实现 GUI。这些是唯一
我正在尝试在我的上网本上运行 Eclipse 以便能够为 Android 进行开发。 您可能已经猜到了,Eclipse 非常慢,并且不容易有效地开发。 我正在使用 Linux Ubuntu 并且我还有
for row, instrument in enumerate(instruments): for col, value in enumerate(instrument):
return not a and not b ^ 我如何以更好的格式表达它 最佳答案 DeMorgan's Law , 也许? return not (a or b) 我认为在这一点上已经足够简单了
我正在尝试让 Font Awesome 图标看起来更 slim https://jsfiddle.net/cliffeee/7L6ehw9r/1/ . 我尝试使用“-webkit-text-strok
假设我有一个名为 vals 的数据框,如下所示: id…………日期…………min_date…… .........最大日期 1…………2016/01/01…………2017/01/01…………2018/
是否有更 Pythonic 的方式来做到这一点?: if self.name2info[name]['prereqs'] is None: se
我有一个函数可以将一些文本打印到它接收到的 ostream&。如果 ostream 以终端为目标,我想让它适应终端宽度,否则默认为某个值。 我现在做的是: 从 ostream 中获取一个 ofstre
这个问题在这里已经有了答案: Should a retrieval method return 'null' or throw an exception when it can't produce
我有这个 bc = 'off' if c.page == 'blog': bc = 'on' print(bc) 有没有更 Pythonic(和/或更短)的方式在 Python 中编写? 最佳
输入:一个包含 50,000 行的 CSV;每行包含 910 列值 0/1。 输出:运行我的 CNN 的数据框。 我编写了一个逐行读取 CSV 的代码。对于每一行,我将数据分成两部分,称为神经元(90
据我所知,with block 会在您退出 block 后自动调用 close(),并且它通常用于确保不会忘记关闭一个文件。 好像没有技术上的区别 with open(file, 'r+') as f
我有一个使用 Entity Framework V6.1.1 的 MVC 5 网站。 Entity Framework DbContext 类和模型最初都在网站项目中。这个项目有 3 个 DbCont
我是编程新手,在尝试通过将 tableView 和关联 View 的创建移动到单独的类并将委托(delegate)和数据源从 VC 移动到单独的类来精简我的 ViewController 时遇到了一些
我是一名优秀的程序员,十分优秀!