【发布时间】:2016-11-01 01:37:03
【问题描述】:
我在 tvOS 上有一个使用 AVPlayerViewController 播放流式音频的应用程序。这工作正常,即使在后台运行。问题是,当 AppleTV 进入睡眠状态并且何时醒来时,播放器被卡住,只有强制退出应用程序才能让我再次开始播放。
我的应用程序是否应该处理某个事件才能正常恢复播放?我应该在文档中寻找什么?
基本代码是:
override func viewDidLoad() {
super.viewDidLoad()
// loading details fron plist
if let stationInfo = readStationSettings() {
stationUrl = stationInfo["url"] as? String
stationName = stationInfo["name"] as? String
stationDescription = stationInfo["description"] as? String
stationImage = stationInfo["image"] as? UIImage
} else {
trackTitle = "Unable to find station details"
return
}
let videoURL = URL(string: stationUrl!)
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true, with: .notifyOthersOnDeactivation)
} catch let error as NSError {
print(error.localizedDescription)
}
playerItem = AVPlayerItem(url: videoURL!)
self.player=AVPlayer(playerItem: playerItem!)
playerLayer=AVPlayerLayer(player: player)
self.player?.play()
}
【问题讨论】:
-
是的,请添加一些代码。
-
@RomanPodymov 我已经更新了问题
标签: swift swift3 tvos apple-tv avplayerviewcontroller