0

I am working on the iOS application. This application base on the NEWS media.

I am playing the small video of highlighted News. I am facing a stranger problem with AVPlayerViewController.

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.

For more clearance please watch this GIF image :

Please visit this link for batter understanding.

This is my code for player.

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.
    }


}
Sankalap Yaduraj Singh
  • 1,167
  • 2
  • 14
  • 32

1 Answers1

0

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.

I guess your problem is in the way you try to show your AVPlayerViewController.

Consider next snippet:

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()
}

This should work. If you need some ui customization you shouldn't use AVPlayerViewController I guess.

UPDATE:

Try adding Reachaility support:

class MyViewController: UIViewController {
  var reachability: Reachability?

  override func viewDidLoad() {
    super.viewDidLoad()

    reachability = try? Reachability.reachabilityForInternetConnection()
    reachability?.whenUnreachable = { _ in
      player.pause()
    }
    try? reachability?.startNotifier()
rkyr
  • 3,131
  • 2
  • 23
  • 38
  • It is not working as for my requirement. When i disconnect from the network the video stops but progress bar continuous play state. – Sankalap Yaduraj Singh Sep 12 '16 at 05:31
  • This is how `AVPlayerViewController` works. If you need to stop player you could combine your code with [Reachability](https://github.com/ashleymills/Reachability.swift/blob/master/Reachability/Reachability.swift). Subscribe to network changes and manage your `player`'s state. – rkyr Sep 12 '16 at 07:55
  • Ok i tried this code and disconnect the wifi but Reachability class does not notify '.whenUnreachable' block , can you suggest me where this code place in my class. – Sankalap Yaduraj Singh Sep 12 '16 at 11:30
  • I've also tried your code with video link (https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4) and problem reproduce(Progress bar continuous play state). – Sankalap Yaduraj Singh Sep 12 '16 at 11:46
  • @SankalapYadurajSingh, sorry, I forgot to include `startNotifier` to example above. Update code should work for you. I've tested it and it works. – rkyr Sep 12 '16 at 12:00
  • I am trying this code in my project and trying to manage. I will tell you after checking. – Sankalap Yaduraj Singh Sep 12 '16 at 12:59
  • @SankalapYadurajSingh I can't help you without any comments or complete code. This example works for me in clean project. – rkyr Sep 13 '16 at 09:12
  • can you send your email id. – Sankalap Yaduraj Singh Sep 13 '16 at 09:37