Playing video in reverse with AVPlayer

I have a recorded video clip that I want to play in reverse (both audio and video). The clip is recorded using a UIImagePickerController with mediaTypes set to kUTTypeMovie. The test clip is just a couple of seconds long but normally I would expect the clips to be 5-10 seconds long.


Playing forward is fine but as soon as I seek to the end of the video file and set the rate of playback to -1.0 the video clip seeks to just before the end of the clip, plays the last few frames forward and then stops. It does not play in reverse.


I have also tried seeking to the middle of the video but all this does is advance the timeline slider to the middle and then it just plays forward to the end.


After I present the player view controller I check if it is ready to use:

print("readyForDisplay = \(playerViewController.readyForDisplay)")


This tells me that all is ready to prepare to play.


I then check if reverse play is possible:

let reversePlay = playerViewController.player!.currentItem?.canPlayReverse print("reversePlay = \(reversePlay)")


This returns TRUE


I then seek to the end of the clip and set the play back rate to -1.0 for reverse play.

playerViewController.player!.seekToTime(playerViewController.player!.currentItem!.asset.duration)

playerViewController.player!.rate = -1.0


I believe having got this far it is ready to play because if I add the following:

let status : AVPlayerItemStatus? = playerViewController.player!.currentItem?.status if status == AVPlayerItemStatus.ReadyToPlay {print("Ready to play") }


It shows me that the clip is ready to play, so I am assuming that seeking to the end of clip (which is only 2 seconds long) has completed.


For good measure I also tried setting setting reversePlaybackEndTime although from the docs it looks as though if not set it defaults kCMTimeInvalid which effectively sets it to kCMTimeZero.


let playerViewController.player!.currentItem!.reversePlaybackEndTime = kCMTimeZero


I then play the clip:

playerViewController.player!.play()


But it won't play in reverse, just forwards.


Any ideas as to what I may be missing here?

Playing video in reverse with AVPlayer
 
 
Q