繁体   English   中英

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

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

我正在研究一个与AVFoundation一起使用的学习项目,该项目处理录音和操纵Audio的播放。 该应用程序可以在模拟器上正常运行,但是在设备上运行时会崩溃。

请注意,它不会立即崩溃。 仅当我尝试操纵要播放的音高时,它才会崩溃。

另外,如果我只是尝试播放录制的音频,它将无法正常工作,但也不会崩溃。

如果您想/可以帮助我,整个项目都在github上, 网址https://github.com/pablomarques/Voice-FX

[项目正在XCode 6.4上运行,并且该设备是运行8.4的iPhone 6]

预先感谢一大堆。

编辑:在此处添加一些代码来节省人们必须通过回购的麻烦(如果您要复制回购,则将回购保存在那里)

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

    }

它在我的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 <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: 与类型NSException(LLDB的未捕获的异常终止 )BT

当我同时使用较旧的AVAudioSession(用于记录声音文件)功能和新的AVAudioEngine(用于应用音高偏移)时,我就遇到了这种情况。

错误-10851是kAudioUnitErr_InvalidPropertyValue,如此处https://developer.apple.com/library/ios/documentation/AudioUnit/Reference/AUComponentServicesReference/

我现在的漏洞修复程序只是在我要使用AudioEngine时停止会话

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

我仍然收到以下错误

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.

但是音调部分正在运行,我的应用程序不再崩溃。 因此,我猜测这只是整理我如何使用两个AVAudio工具的问题。

暂无
暂无

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

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