I want to play video backward in AVPlayer. I have tried with changing rates property to -1.0, and although it did work it was not smooth. Is there any way through which I can smoothly play videos backward?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- Safari blocks play() on video despite being called
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
You have to reach at the end of the current item and then set the rate to the negative value. Something like this:
-(void)reversePlay { CMTime durTime = myPlayer.currentItem.asset.duration; if (CMTIME_IS_VALID(durTime)) { [myPlayer seekToTime:durTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; [myPlayer setRate:-1.0]; } else NSLog(@"Invalid time"); }
source: https://stackoverflow.com/a/16104363/701043
As stated in the comments, the problem is with keyframes and the fact that most codecs are not designed to play backwards. There are 2 options for re-encoding the video that doesn't require you to actually reverse the video in editing.
Note that either of this options will result in larger file sizes compared to typical "keyframe every x frames" encoded video.