在 iPhone 上使用 AVPlayer,SeekToTime 只会为我重新启动视频
我试图让一个相当短的视频(0.05 秒)从 0.02 秒开始播放。我使用下面的代码:
CMTime tolerance = CMTimeMake(0,1);
CMTime replayBeginTime = CMTimeMake(1, 50);
[player seekToTime: replayBeginTime toleranceBefore: tolerance toleranceAfter: tolerance];
[player play];
其中玩家是 AVPlayer*。视频从头到尾播放得很好,然后我点击一个按钮返回到大约一半的位置,它应该从那里开始播放,但每次它都会重新启动视频。
我不能 100% 确定我正确使用 CMTimeMake。
任何帮助弄清楚我做错了什么的帮助将不胜感激。
I am trying to get a fairly short video (0.05 seconds) to play from 0.02 seconds. I use the code below:
CMTime tolerance = CMTimeMake(0,1);
CMTime replayBeginTime = CMTimeMake(1, 50);
[player seekToTime: replayBeginTime toleranceBefore: tolerance toleranceAfter: tolerance];
[player play];
Where player is an AVPlayer*. The video plays fine from start to finish and then i hit a button to go back to roughly the half way point and it should play from there, but every time it just restarts the video.
I'm not a 100% sure I'm using CMTimeMake correctly.
Any help figuring out what I'm doing wrong would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在创建一个值为 1/50 = 0.02 的 CMTime,因此您正确使用了 CMTimeMake。但我认为也许你应该使用 CMTimeMakeWithSeconds 来代替。因为 CMTimeMake 只能采用秒的整数值,而 CMTimeMakeWithSeconds 可以采用浮点数。
你应该像这样使用它。
祝你好运。
You are creating a CMTime with a value of 1/50 = 0.02, so you are using CMTimeMake correctly. But I think maybe you should use CMTimeMakeWithSeconds instead. Because CMTimeMake can only take an integer value of seconds, while CMTimeMakeWithSeconds can take a float.
You should use it like this.
Good luck.