我想打在我的項目的音頻在做IOS(SWIFT語言)。我不能播放音頻因錯誤如何解決線程1:EXC_BAD_INSTRUCTION(代碼= EXC_I386_INVOP,子碼=爲0x0)
線程1:EXC_BAD_INSTRUCTION(代碼= EXC_I386_INVOP,子碼=爲0x0)
我能起到同樣的音頻時不將其分離。但是,當我將它添加到我的項目獲取上述錯誤。我嘗試用不同的代碼播放音頻。但同樣的錯誤在同一行中重複出現。
@IBAction func playaudio(sender:AnyObject)
{
var ButtonAudioPlayer: AVAudioplayer!
let path = NSBundle.mainBundle()pathResource("ButtonAudio.wav",ofType:nil)! // error
let url = NSURL(fileURLWithPath: path)
do
{
let ButtonAudioPlayer1 = try! AVAudioPlayer(contesOfURL:url)
ButtonAudioPlayer = ButtonAudioPlayer1
ButtonAudioPlayer1.play()
}
}
我試過這種方式。但我仍然在同一行中得到同樣的錯誤。 – sitara
嘗試使用'URLForResource(_:withExtension :)'並讓我知道它是否會改變任何東西。 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/#//apple_ref/occ/instm/NSBundle/URLForResource:withExtension: –
始終打印「沒有這樣的文件「 – sitara