我正在使用Swift开发一个项目,尝试启动AVPlayer,但出现异常并显示
AudioHardware.cpp:1200:AudioObjectRemovePropertyListener:AudioObjectRemovePropertyListener:没有具有给定ID 0的对象。
我猜问题出在我的URL上。以下是我的代码:
func initPlayer() {
let url:NSURL = NSURL(string:"https://purelight1-163000.appspot.com/api/user/v2/media/track/60/sample")!
self.playerItem = AVPlayerItem(url: url as URL)
self.player=AVPlayer(playerItem: self.playerItem!)
let playerLayer=AVPlayerLayer(player: self.player!)
playerLayer.frame = CGRect(x: 0, y: 0, width: 10, height: 50) // actually this player layer is not visible
self.view.layer.addSublayer(playerLayer)
}
NSURL
然后将其转换为URL
?你应该只需简单地执行let url= URL(string:"https://purelight1-163000.appspot.com/api/user/v2/media/track/60/sample")!
。 - Dávid Pásztor