【发布时间】:2015-08-19 23:28:10
【问题描述】:
我正在开展一个与 AVFoundation 合作的学习项目,并处理音频的录制和操作。该应用在模拟器上运行良好,但在设备上运行时崩溃。
请注意,它不会立即崩溃。只有当我尝试操纵要播放的声音的音高时它才会崩溃。
另外,如果我只是尝试播放录制的音频,它不会工作,但也不会崩溃。
如果你想/可以帮助我,整个项目都在 github 上,https://github.com/pablomarques/Voice-FX
[项目在 XCode 6.4 上运行,设备是运行 8.4 的 iPhone 6]
提前感谢一大堆。
编辑:在此处添加一些代码以省去人们必须通过 repo 的麻烦(如果您想复制它,请将 repo 保留在那里)
它在模拟器上工作得很好,它正在我的脑海里。:(
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var audioPlayer:AVAudioPlayer!
var receivedAudio:AudioRecording!
var audioEngine:AVAudioEngine!
var audioFile:AVAudioFile!
override func viewDidLoad() {
super.viewDidLoad()
if let path = receivedAudio.filePathURL {
audioPlayer = AVAudioPlayer(contentsOfURL: path, error: nil)
audioPlayer.enableRate = true
audioEngine = AVAudioEngine()
audioFile = AVAudioFile(forReading: path, error: nil)
println(path)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playSlowSound(sender: AnyObject) {
playSound(0.35)
println("clicking works")
}
@IBAction func playFastSound(sender: AnyObject) {
playSound(3.0)
}
@IBAction func chipMunkSound(sender: AnyObject) {
playAudioWithVariablePitch(1000.0)
}
@IBAction func vaderSound(sender: AnyObject) {
playAudioWithVariablePitch(-1000.0)
}
@IBAction func stopSounds(sender: AnyObject) {
audioPlayer.stop()
audioPlayer.currentTime = 0
}
func playSound(soundSpeed: Float) {
audioPlayer.stop()
audioPlayer.currentTime = 0
audioPlayer.rate = soundSpeed
audioPlayer.prepareToPlay()
audioPlayer.play()
println("playing")
}
func playAudioWithVariablePitch(pitch: Float){
audioPlayer.stop()
audioEngine.stop()
audioEngine.reset()
var audioPlayerNode = AVAudioPlayerNode()
audioEngine.attachNode(audioPlayerNode)
var changePitchEffect = AVAudioUnitTimePitch()
changePitchEffect.pitch = pitch
audioEngine.attachNode(changePitchEffect)
audioEngine.connect(audioPlayerNode, to: changePitchEffect, format: nil)
audioEngine.connect(changePitchEffect, to: audioEngine.outputNode, format: nil)
audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(nil)
audioPlayerNode.play()
}
它在我的 AppDelegate.swift 文件中显示绿色错误断点,这很奇怪。
class AppDelegate: UIResponder, UIApplicationDelegate {
这是我得到的错误信息:
2015-08-20 05:32:55.506 Voice FX[2265:548015] 05:32:55.506 错误:[0x19bb13310] >aurioc> 806:失败:-10851(启用 2,outf inf) 2015-08-20 05:32:55.509 语音 FX[2265:548015] 05:32:55.508 错误:[0x19bb13310] >aurioc> 806:失败:-10851(启用 2,outf inf) 2015-08-20 05:32:55.512 语音 FX[2265:548015] 05:32:55.512 错误:[0x19bb13310] >aurioc> 806:失败:-10851(启用 2,outf inf) 2015-08-20 05:32:55.513 语音 FX[2265:548015] 05:32:55.512 错误:[0x19bb13310] AVAudioEngineGraph.mm:2417:PerformCommand:错误 -10851 2015-08-20 05:32:55.517 Voice FX[2265:548015] * 由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“错误 -10851” * 首先抛出调用栈: (0x18563022c 0x1972fc0e4 0x1856300ec 0x183f6e008 0x183fa07ac 0x183fa8a54 0x183fa99dc 0x183f9d9b4 0x183f9da94 0x183f9da94 0x183f9e9f4 0x183fa2140 0x183f9292c 0x183f91f98 0x183f91f28 0x10006c03c 0x10006b20c 0x10006b264 0x18a0e11ec 0x18a0ca2c8 0x18a0e0b88 0x18a0e0814 0x18a0d9d50 0x18a0acf74 0x18a34e124 0x18a0ab488 0x1855e7f8c 0x1855e7230 0x1855e52e0 0x185510f74 0x18ef6b6fc 0x18a112d94 0x10006f3f8 0x1979a6a08) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb) bt
【问题讨论】:
-
要处理很多代码...您是否可以缩小可能导致此问题的原因?
-
当然,蒂姆。对此感到抱歉,我现在将用我认为问题所在的代码修改问题。但我不是 100% 确定,因为这可能是我录制音频的初始视图的问题。
-
快速更新,当我在手机上运行应用程序时,它不允许我在应用程序内通过硬件按钮控制音量。
-
用有关崩溃的详细信息更新您的问题。错误信息是什么?哪一行代码导致了错误?
-
@rmaddy 这是一个奇怪的错误。已经为此苦苦挣扎了几个小时:/ 将尽快编辑问题
标签: ios iphone swift avfoundation