我正试图在我的AVPlayer中寻找前进和倒退。这是一种工作,但确定pan在哪里转换为资产长度的基本数学是错误的。有人能提供帮助吗?
- (void) handlePanGesture:(UIPanGestureRecognizer*)pan{
CGPoint translate = [pan translationInView:self.view];
CGFloat xCoord = translate.x;
double diff = (xCoord);
//NSLog(@"%F",diff);
CMTime duration = self.avPlayer.currentItem.asset.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
CGFloat gh = 0;
if (diff>=0) {
//If the difference is positive
NSLog(@"%f",diff);
gh = diff;
} else {
//If the difference is negative
NSLog(@"%f",diff*-1);
gh = diff*-1;
}
float minValue = 0;
float maxValue = 1024;
float value = gh;
double time = seconds * (value - minValue) / (maxValue - minValue);
[_avPlayer seekToTime:CMTimeMakeWithSeconds(time, 10) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
//[_avPlayer seekToTime:CMTimeMakeWithSeconds(seconds*(Float64)diff , 1024) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}发布于 2016-08-04 14:48:00
您没有规范触摸位置和相应的时间值。两者之间是否有1:1的关系?这不可能。
获取pan手势的最小和最大触摸位置值以及资产持续时间的最小和最大值(显然,从0到视频长度),然后应用以下公式将触摸位置转换为搜索时间:
// Map
#define map(x, in_min, in_max, out_min, out_max) ((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)下面是我编写的使用该公式的代码:
- (IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateChanged){
CGPoint location = [sender locationInView:self];
float nlx = ((location.x / ((CGRectGetMidX(self.frame) / (self.frame.size.width / 2.0)))) / (self.frame.size.width / 2.0)) - 1.0;
//float nly = ((location.y / ((CGRectGetMidY(self.view.frame) / (self.view.frame.size.width / 2.0)))) / (self.view.frame.size.width / 2.0)) - 1.0;
nlx = nlx * 2.0;
[self.delegate setRate:nlx];
}
}我挑选了显示速度的标签,以及在你擦洗的时候出现的播放图标,它会根据你平移视频的速度或速度来改变大小。虽然你没有要求,但如果你想要的话,就去问吧。
哦,“倍-2”因子的目的是向发送到委托的setRate方法的pan手势值中添加一个加速曲线。你可以使用任何公式,即使是一个实际的曲线,如pow(nlx,2.0)或其他什么.
发布于 2014-10-03 02:31:26
如果你想使它更精确和有用,你应该实现不同的“敏感水平”。
苹果用他们的滑块做这件事:如果你从滑块上拖开,然后拖到一边,视频移动的速度就会改变。你离滑块越远,它就越精确/你能接触到的越少。
https://stackoverflow.com/questions/26046946
复制相似问题