简体   繁体   English

AVPlayer反向播放

[英]AVPlayer Reverse Playback

How would one go about getting an AVPlayer object to play its video content in reverse? 如何让AVPlayer对象反向播放其视频内容? The AVPlayerItem class has a property called "reversePlaybackEndTime," which makes me think that reverse playback is thus possible, but I can't seem to find anything in the docs about actually doing it. AVPlayerItem类有一个名为“reversePlaybackEndTime”的属性,这使我认为反向回放是可能的,但我似乎无法在文档中找到关于实际执行它的任何内容。

You can reverse play like this as queuePlayer is AVPlayer : 您可以像这样reverse play因为queuePlayerAVPlayer

Firstly get to end of video 首先到video end

CMTime durTime = self.queuePlayer.currentItem.asset.duration;
durationTime = CMTimeGetSeconds(durTime);
//NSLog(@"durationTime :%f : %f",durTime);
if (CMTIME_IS_VALID(durTime))
    [self.queuePlayer seekToTime:durTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
else
    NSLog(@"In valid time");

Now set Rate of AVPlayer to negative value 现在将AVPlayer Rate设置为negative

[self.queuePlayer setRate:-1];

When you send 'play' message to the AVPlayer object it starts playing and this is equivalent to setting the rate property to 1.0. 当您向AVPlayer对象发送'play'消息时,它开始播放,这相当于将rate属性设置为1.0。 Have you tried to set that property to -1.0? 您是否尝试将该属性设置为-1.0? I haven't Mac at the moment to test it, so if this doesn't work I'll remove my answer. 我目前还没有Mac测试它,所以如果这不起作用,我将删除我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM