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

 

posted @ 2014-11-15 14:50  wuchunyang  阅读(404)  评论(0编辑  收藏  举报