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