在forwardPlaybackEndTime之后恢复AVPlayer [英] Resume AVPlayer after forwardPlaybackEndTime

查看:239
本文介绍了在forwardPlaybackEndTime之后恢复AVPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了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.

我将为您保留所有AVPlayer设置代码(大部分内容取自

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆