尝试使用 Swift AVPlayer 播放音频

Trying to play audio with Swift AVPlayer

这是我当前的ViewController:

import UIKit
import AVFoundation

class SecondViewController: UIViewController {
    override func viewDidLoad() {
        var player = AVPlayer()
            let url = "http://www.nasa.gov/mp3/640149main_Computers%20are%20in%20Control.mp3"
            let playerItem = AVPlayerItem( URL:NSURL( string:url ) )
            player = AVPlayer(playerItem:playerItem)
            player.rate = 1.0;
            player.play()
    }
}

当我在模拟器中 运行 时没有音频,可能是 iOS sim 不播放音频,还是我的代码有问题?

移行:

    var player = AVPlayer()

...所以它在之前行:

override func viewDidLoad() {