How to change video link while streaming depending on network speed AVPlayer Swift

Viewed 498

I have an Array of URLs with different video screen quality and I choose the link depending on the current network speed the user is on. As network changes quite often even during playback, how would I change the link during streaming?

This is my code below, the link is received after we know which network the user is:

 NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
        let player = AVPlayer(URL: NSURL(string: stringUrl)!)
        self.playerViewController = AVPlayerViewController()
        self.playerViewController!.player = player
        currentView.view.window?.rootViewController?.presentViewController(self.playerViewController!, animated: true, completion: nil)
    })
0 Answers
Related