简体   繁体   English

IOs App可在模拟器上运行,但在设备上崩溃(主要是使用AVFoundation)

[英]IOs App works on simulator but crashes on device (mainly using AVFoundation)

I'm working on a learning project that works with AVFoundation and deals with recording and manipulating the playback of Audio. 我正在研究一个与AVFoundation一起使用的学习项目,该项目处理录音和操纵Audio的播放。 The app runs fine on the simulator but it crashes when running on the device. 该应用程序可以在模拟器上正常运行,但是在设备上运行时会崩溃。

Mind you, it doesn't crash instantly. 请注意,它不会立即崩溃。 It only crashes when I try to manipulate the pitch of the sound to be played. 仅当我尝试操纵要播放的音高时,它才会崩溃。

Also if I just try to play back the audio that was recorded, it won't work, but it also won't crash. 另外,如果我只是尝试播放录制的音频,它将无法正常工作,但也不会崩溃。

If you want/can help me, the whole project is on github, at https://github.com/pablomarques/Voice-FX 如果您想/可以帮助我,整个项目都在github上, 网址https://github.com/pablomarques/Voice-FX

[Project is running on XCode 6.4 and the device is an iPhone 6 running 8.4] [项目正在XCode 6.4上运行,并且该设备是运行8.4的iPhone 6]

Thanks a whole bunch in advance. 预先感谢一大堆。

Edit: Adding some of the code here to save people the hassle of having to go through the repo (will keep repo there if you want to replicate it) 编辑:在此处添加一些代码来节省人们必须通过回购的麻烦(如果您要复制回购,则将回购保存在那里)

It works just fine on the Simulator, it is doing my head in. :( 它在Simulator上工作得很好,它正在使我头脑清醒。:(

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

    }

it shows the green error breakpoint at my AppDelegate.swift file which is weird. 它在我的AppDelegate.swift文件中显示了绿色错误断点,这很奇怪。

class AppDelegate: UIResponder, UIApplicationDelegate {

and this is the error message i get: 这是我得到的错误信息:

2015-08-20 05:32:55.506 Voice FX[2265:548015] 05:32:55.506 ERROR: [0x19bb13310] >aurioc> 806: failed: -10851 (enable 2, outf< 2 ch, 0 Hz, Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>) 2015-08-20 05:32:55.509 Voice FX[2265:548015] 05:32:55.508 ERROR: [0x19bb13310] >aurioc> 806: failed: -10851 (enable 2, outf< 2 ch, 44100 Hz, Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>) 2015-08-20 05:32:55.512 Voice FX[2265:548015] 05:32:55.512 ERROR: [0x19bb13310] >aurioc> 806: failed: -10851 (enable 2, outf< 2 ch, 44100 Hz, Float32, non-inter> inf< 2 ch, 0 Hz, Float32, non-inter>) 2015-08-20 05:32:55.513 Voice FX[2265:548015] 05:32:55.512 ERROR: [0x19bb13310] AVAudioEngineGraph.mm:2417: PerformCommand: error -10851 2015-08-20 05:32:55.517 Voice FX[2265:548015] * Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -10851' * First throw call stack: (0x18563022c 0x1972fc0e4 0x1856300ec 0x183f6e008 0x183fa07ac 0x183fa8a54 0x183fa99dc 0x183f9d9b4 2015-08-20 05:32:55.506 Voice FX [2265:548015] 05:32:55.506错误:[0x19bb13310]> aurioc> 806:失败:-10851(启用2,outf <2 ch,0 Hz,Float32, non-inter> inf <2 ch,0 Hz,Float32,non-inter>)2015-08-20 05:32:55.509 Voice FX [2265:548015] 05:32:55.508错误:[0x19bb13310]> aurioc> 806 :失败:-10851(启用2,outf <2 ch,44100 Hz,Float32,非内部> inf <2 ch,0 Hz,Float32,非内部>)2015-08-20 05:32:55.512 Voice FX [2265:548015] 05:32:55.512错误:[0x19bb13310]> aurioc> 806:失败:-10851(启用2,outf <2 ch,44100 Hz,Float32,non-inter> inf <2 ch,0 Hz, Float32,非inter>)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 0x183fa8ac54x 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: terminating with uncaught exception of type NSException (lldb) bt 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

I just ran into this, when I was working with both the older AVAudioSession (for recording a sound file) functionalities AND the new AVAudioEngine (for applying a voice pitch shift). 当我同时使用较旧的AVAudioSession(用于记录声音文件)功能和新的AVAudioEngine(用于应用音高偏移)时,我就遇到了这种情况。

The error -10851 is kAudioUnitErr_InvalidPropertyValue as seen here https://developer.apple.com/library/ios/documentation/AudioUnit/Reference/AUComponentServicesReference/ 错误-10851是kAudioUnitErr_InvalidPropertyValue,如此处https://developer.apple.com/library/ios/documentation/AudioUnit/Reference/AUComponentServicesReference/

My hacky fix right now is just stopping my session when I'm about to use the AudioEngine 我现在的漏洞修复程序只是在我要使用AudioEngine时停止会话

ie

self.avSession?.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
self.avSession?.setActive(false, error: nil)

I still get the following error 我仍然收到以下错误

AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

But the voice pitch part is working and my app no longer crashes. 但是音调部分正在运行,我的应用程序不再崩溃。 So I'm guessing that it's just a matter of tidying up how I'm using the two AVAudio tools. 因此,我猜测这只是整理我如何使用两个AVAudio工具的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM