Using AVPlayer in Swift. No error but no sound playing on iPhone.
I'm new to Swift. I will appreciate a response.
Here is my code:
import UIKit
import AVFoundation
class PlayerViewController: UIViewController {
// This time, we'll declare avPlayer as an instance variable,
// which means it exists as long as our view controller exists.
var avPlayer: AVPlayer!
override func viewDidLoad() {
super.viewDidLoad()
print("Connecting...")
// If you'd rather not use this sound file,
// replace the string below with the URL of some other MP3.
let urlString = "http://live.canstream.co.uk:8000/bangradio.mp3"
let url = NSURL(string: urlString)!
avPlayer = AVPlayer(URL: url)
print("Connected to One Radio!")
avPlayer.play()
print("Now playing...")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}