import UIKit
import AVFoundation
class MainViewController: UIViewController,ViewController2Delegate,AVAudioPlayerDelegate {
@IBOutlet weak var b1: UIButton!
@IBAction func b1_pressed(sender: AnyObject) {
NSLog("hi");
}
override func viewDidLoad() {
super.viewDidLoad()
var player: AVPlayer! = nil
var steamingURL:NSURL! = NSURL(string:"http://yflvr.com:8080/data/songs1/mp3/16287239.mp3")
player = AVPlayer(URL: steamingURL)
player.play()
}
答案 0 :(得分:1)
在viewDidLoad完成后,您的AVPlayer对象将被释放,因为您已将播放器分配给局部变量。您需要为玩家创建一个属性。
@IBOutlet weak var b1: UIButton!
@IBAction func b1_pressed(sender: AnyObject) {
NSLog("hi");
}
var player: AVPlayer!
override func viewDidLoad() {
super.viewDidLoad()
var steamingURL:NSURL! = NSURL(string:"http://yflvr.com:8080/data/songs1/mp3/16287239.mp3")
player = AVPlayer(URL: steamingURL)
player.play()
}