首页 > 代码库 > swift 播放声音

swift 播放声音

代码如下

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

 

swift 播放声音