iOS中的AVPlayerViewController播放/暂停问题 [英] AVPlayerViewController play/pause issue in iOS
问题描述
我正在使用iOS应用程序.此应用程序基于NEWS媒体.
I am working on the iOS application. This application base on the NEWS media.
我正在播放突出显示的新闻的小型视频.我遇到AVPlayerViewController
的陌生人问题.
I am playing the small video of highlighted News. I am facing a stranger problem with AVPlayerViewController
.
当我播放视频时,一切都很好.当我离线时,缓冲视频可以完美播放播放缓冲视频后,视频停止,但progress bar(Slider)
在视频停止的同时一直处于播放状态.
When i play the video everything is fine. When i go to offline the buffer video play perfect & after the play buffer video, the video stops but the progress bar(Slider)
continuously in play state while the video has been stopped.
有关更多间隙,请观看此GIF图片:
For more clearance please watch this GIF image :
这是我给玩家的代码.
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.
}
}
推荐答案
我尝试了您的代码,甚至看不到gif图片. 我还尝试了使用另一个视频链接的代码( https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 ),问题没有得到再现.
I've tried your code and I couldn't even see picture from your gif. I've also tried your code with another video link (https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4) and problem wasn't reproduced.
我想您的问题在于您尝试显示AVPlayerViewController
的方式.
I guess your problem is in the way you try to show your 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
.
This should work. If you need some ui customization you shouldn't use AVPlayerViewController
I guess.
更新:
尝试添加 Reachaility 支持:
class MyViewController: UIViewController {
var reachability: Reachability?
override func viewDidLoad() {
super.viewDidLoad()
reachability = try? Reachability.reachabilityForInternetConnection()
reachability?.whenUnreachable = { _ in
player.pause()
}
try? reachability?.startNotifier()
这篇关于iOS中的AVPlayerViewController播放/暂停问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!