gpt4 book ai didi

ios - 异常 com.apple.coreaudio.avfaudio 原因 : error -50

转载 作者:IT王子 更新时间:2023-10-29 05:53:58 28 4
gpt4 key购买 nike

当我尝试播放不同音高的音频时,我收到此消息: enter image description here

我在谷歌上搜索了那个错误,但没有成功。如果我设置断点它就停在这里: enter image description here

我测试打印所有对象以查看是否有问题,但我没有找到任何东西。最莫名其妙的是,只在我的iphone6+上出现过,在我测试过的其他手机上都没有坏。然后搜索我查看的项目以添加此音效,它是这样的: https://github.com/atikur/Pitch-Perfect如果你运行它,它就会工作,直到你改变......

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, error: &error)

收件人:

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: &error)

然后 boom(仅在连接到 XCODE 的真实设备中,它在模拟器中工作):

2015-03-21 11:56:13.311 Pitch Perfect[1237:607678] 11:56:13.311 错误:[0x10320c000] AVAudioFile.mm:496:-[AVAudioFile readIntoBuffer:frameCount:error:]: error -502015-03-21 11:56:13.313 Pitch Perfect[1237:607678] * 由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“错误 -50”* 首先抛出调用栈:(0x18687a530 0x1978040e4 0x18687a3f0 0x1851ea6c0 0x185232d38 0x1852130f8 0x185212ccc 0x100584fd4 0x100584f94 0x10058fdb8 0x1005882c4 0x1005925d4 0x100592208 0x198037dc8 0x198037d24 0x198034ef8)libc++abi.dylib:以 NSException 类型的未捕获异常终止

真正奇怪的是这个屏幕截图,出于某种原因在打印 audioEngine 之后,audioEngine.outputNode 变为 nil? weird bug

最佳答案

我有同样的错误...我已经创建了一个“sound.swift”类,我的 View Controller 将实例化...我决定简化一切并专注于让声音正常工作。所以我在 View Controller 中放入了以下代码并且它起作用了:

//获取录音文件

var pitchPlayer = AVAudioPlayerNode()
var timePitch = AVAudioUnitTimePitch()
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] as! String

var pathArray = [dirPath, String("son.wav")]

filePath = NSURL.fileURLWithPathComponents(pathArray)

audioFile = AVAudioFile(forReading: filePath.filePathURL, error: nil)

audioEngine = AVAudioEngine()

audioEngine.attachNode(pitchPlayer)
audioEngine.attachNode(timePitch)


//Create a session
var session=AVAudioSession.sharedInstance()
session.setCategory(AVAudioSessionCategoryPlayAndRecord,error:nil)

//output audio
session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error: nil)

audioEngine.connect(pitchPlayer, to: timePitch, format: audioFile.processingFormat)
audioEngine.connect(timePitch, to: audioEngine.outputNode, format: audioFile.processingFormat)

pitchPlayer.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(&audioError)

pitchPlayer.play()

关于ios - 异常 com.apple.coreaudio.avfaudio 原因 : error -50,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29181953/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com