swift 播放声音
代码如下
import AVFoundation class ViewController: UIViewController { var audioPlayer:AVAudioPlayer? override func viewDidLoad() { super.viewDidLoad() let url = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("car", ofType:"mp3")) audioPlayer = AVAudioPlayer(contentsOfURL:url, error:nil) audioPlayer!.play() } }