我正在开发iOS应用程序。该应用程序基于NEWS媒体。
我正在播放突出显示的新闻的小视频。我遇到了AVPlayerViewController
的陌生人问题。
当我播放视频时,一切都很好。当我离线时,缓冲视频播放完美&在播放缓冲区视频之后,视频停止,但progress bar(Slider)
在视频停止时一直处于播放状态。
如需更多清关,请观看此GIF图片:
Please visit this link for batter understanding.
这是我的播放器代码。
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.playVideo()
}
func playVideo(){
let videoURL = NSURL(string: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8")
let player = AVPlayer(URL: videoURL!)
let playerController = AVPlayerViewController()
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:0)
我已经尝试过您的代码,我甚至无法看到您的GIF图片。 我还尝试使用其他视频链接(https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4)来解决您的问题,但问题未被重现。
我猜您的问题与您尝试展示AVPlayerViewController
的方式有关。
考虑下一个片段:
let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(URL: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player!.play()
}
这应该有效。如果您需要一些ui自定义,我不应该使用AVPlayerViewController
。
更新:
尝试添加Reachaility支持:
class MyViewController: UIViewController {
var reachability: Reachability?
override func viewDidLoad() {
super.viewDidLoad()
reachability = try? Reachability.reachabilityForInternetConnection()
reachability?.whenUnreachable = { _ in
player.pause()
}
try? reachability?.startNotifier()