Reputation: 345
Here's my current 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()
}
}
When I run this in the simulator I get no audio, could it be that the iOS sim doesn't play audio, or an issue with my code?
Upvotes: 5
Views: 10691
Reputation: 535140
Move the line:
var player = AVPlayer()
... so that it is before the line:
override func viewDidLoad() {
Upvotes: 9