AVPlayer 视频 SeekToTime
我正在使用 AVPlayer 使用滑块和一些按钮来播放我的视频。 这是我使用按钮前进和后退的方法。
-(IBAction)MoveForward
{
//int value = timeSlider.value*36000 + 10;
//CMTime newTime = CMTimeMakeWithSeconds(value, playspeed);
//CMTime newTime = CMTimeMake(value,(playspeed*timeSlider.maximumValue));
CMTime newTime = CMTimeMakeWithSeconds(timeSlider.value, playspeed);
newTime.value += 60;
[player seekToTime: newTime];
}
-(IBAction)MoveBackward
{
CMTime newTime = CMTimeMakeWithSeconds(timeSlider.value-1, playspeed);
[player seekToTime: newTime];
}
我的问题是 Seek 的时间无法正常工作。基于秒导航到下一帧。我需要仔细移动下一帧。帮我...
I'm using AVPlayer for play my video using slider and Some Buttons.
Here is my methods for moving forward and backward using buttons.
-(IBAction)MoveForward
{
//int value = timeSlider.value*36000 + 10;
//CMTime newTime = CMTimeMakeWithSeconds(value, playspeed);
//CMTime newTime = CMTimeMake(value,(playspeed*timeSlider.maximumValue));
CMTime newTime = CMTimeMakeWithSeconds(timeSlider.value, playspeed);
newTime.value += 60;
[player seekToTime: newTime];
}
-(IBAction)MoveBackward
{
CMTime newTime = CMTimeMakeWithSeconds(timeSlider.value-1, playspeed);
[player seekToTime: newTime];
}
My Problem on this is the time to Seek is not working properly. That navigate to next frame based on seconds. I need to move next frame minutely. Help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太理解你的代码,你真的不需要单独的方法来向前和向后移动,你可以对两者使用相同的方法。我有一个可用的 AVPlayer 电影播放器,我将向您展示我是如何完成滑块部分的。
就是这样,这段代码中有两个问题,首先,duration 属性返回一个 CMTime 变量,您必须将其转换为浮点数,另外,这返回原始秒数,您必须将其转换为 h:mm :ss 如果你想显示时间标签。其次,updateSlider 方法每秒由计时器触发。
祝你好运。
I don't really understand your code, you don't really need separate methods to move forwards and backwards, you can use the same one for both. I've got a working AVPlayer Movie Player, I'll show you how I did the slider part.
And that's it, there are two gotchas in this code, first, the duration property returns a CMTime variable, you have to convert it to a float, also, this returns the raw number of seconds, you have to convert it to h:mm:ss if you want to display time labels. Second, the updateSlider method is triggered by a timer every second.
Good Luck.
以下代码片段对我有用:
The following snippet of code worked for me: