2
我想把音頻放到我的應用程序中,然後放入下面的代碼,並將我的mp3音頻文件放入我的資產文件夾中,並且它墜毀了:「EXC_BAD_INSTRUCTION(code = EXC_1386_INVOP ,子代碼= 0x0)「Swift音頻實施崩潰:「EXC_BAD_INSTRUCTION」
我真的可以使用一些幫助,我做錯了/我需要把音頻文件。 我的代碼:
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ScrollView.scrollEnabled = true
ScrollView.contentSize = CGSize(width:473, height: 112)
changer = 0
tapView.hidden = true
yoohooView.hidden = true
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Untitled", ofType: "mp3")!) //Crashes here
println(alertSound)
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}