I'm developing an music app written in swift 2.0.
Right now, I'm implementing video player part with AVPlayer.
I wanted to add a feature that if user swipes down any place in the modal(in the movie player), the modal gets dismissed downward. (like as ios youtube player; they don't actually dissmiss the player though)
I researched how to implement this feature and found the solution below
Stackoverflow answer : In iOS, how to drag down to dismiss a modal?
Full Tutorial : http://www.thorntech.com/2016/02/ios-tutorial-close-modal-dragging/
It works well but there is a problem that AVPlayer is freezing when the pan gesture is made (while holding a finger on the screen). The Audio is playing normally. Only the video is freezing.
Here is the code handling pan gestures.
@IBAction func handleGesture(sender: UIPanGestureRecognizer) {
let percentThreshold:CGFloat = 0.2
// convert y-position to downward pull progress (percentage)
let translation = sender.translationInView(view)
let verticalMovement = translation.y / view.bounds.height
let downwardMovement = fmaxf(Float(verticalMovement), 0.0)
let downwardMovementPercent = fminf(downwardMovement, 1.0)
let progress = CGFloat(downwardMovementPercent)
guard let interactor = interactor else { return }
switch sender.state {
case .Began:
interactor.hasStarted = true
dismissViewControllerAnimated(true, completion: nil)
case .Changed:
interactor.shouldFinish = progress > percentThreshold
interactor.updateInteractiveTransition(progress)
case .Cancelled:
interactor.hasStarted = false
interactor.cancelInteractiveTransition()
case .Ended:
interactor.hasStarted = false
if interactor.shouldFinish {
interactor.finishInteractiveTransition()
} else {
interactor.cancelInteractiveTransition()
}
default:
break
}
}
After "dismissViewControllerAnimated(true, completion: nil)" is called (case .Began:), "currentVideoFrameRate" (avPlayer.currentItem?.tracks.first?.currentVideoFrameRate) is reduced from approx. 29 to 4.
It seems the rate controlled internally. I still don't know how to prevent from lowering the frame rate.
I want to make AVPlayer play video normally even if it is on transitioning (.Changed status)
Does anyone know how to fix this issue?
Thanks!