在forwardPlaybackEndTime之后恢复AVPlayer [英] Resume AVPlayer after forwardPlaybackEndTime
问题描述
我创建了AVPlayer
并将forwardPlaybackEndTime
设置为在给定的时间戳记下停止本地视频播放.果然,视频在我要求的时间停止播放.一切都很好.
I've created an AVPlayer
and set the forwardPlaybackEndTime
to make a local video stop at a given timestamp. Sure enough, the video stops at the time I've requested. All good.
现在,我希望视频在用户操作(例如触摸按钮)触发后继续播放.不幸的是,如果不从头开始重新播放视频,我似乎无法实现.
Now I want the video to continue when triggered by a user action (touching a button, for example). Unfortunately, I can't seem to make that happen without the video restarting from the beginning.
I'll spare you all of the AVPlayer setup code (which is mostly taken from the AV Foundation Programming Guide), but given these variables:
AVPlayer *avPlayer;
AVPlayerItem *playerItem;
我可以这样设置结束时间:
I can set the end time like so:
[playerItem setForwardPlaybackEndTime: CMTimeMake(30, 30)];
要尝试简历,我尝试了以下方法:
To attempt the resume, I've tried this:
[playerItem setForwardPlaybackEndTime: CMTimeMake(30, 30)];
[avPlayer setRate: 1.0];
没有骰子.我也尝试设置结束时间并调用play
.没运气.我试过seekToTime
将播放头放在视频停止的地方,以防万一.不是.
No dice. I've also tried setting the end time and calling play
. No luck. I've tried seekToTime
to put the playhead at the place where the video stopped in case that would help. It doesn't.
有人可以解释如何进行这项工作吗?谢谢!
Can someone please explain how to make this work? Thanks!
推荐答案
尝试将forwardPlaybackEndTime
设置回默认值kCMTimeInvalid
,然后继续播放视频.
Try setting the forwardPlaybackEndTime
back to the default value, kCMTimeInvalid
then continue to play the video.
[playerItem setForwardPlaybackEndTime: kCMTimeInvalid];
[playerItem seekToTime: CMTimeMake(30, 30) toleranceBefore: kCMTimeZero toleranceAfter: kCMTimeZero];
[avPlayer play];
这篇关于在forwardPlaybackEndTime之后恢复AVPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!