代码如下
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() } }
时间: 2024-10-06 13:26:01