Resume AVPlayer after forwardPlaybackEndTime

余生长醉 提交于 2019-12-11 21:02:21

问题


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];

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!


回答1:


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];


来源:https://stackoverflow.com/questions/26225334/resume-avplayer-after-forwardplaybackendtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!