- (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];}解决方法 您没有规范化触摸位置和相应的时间值.这两者之间有1:1的关系吗?那是不可能的.
获取平移手势的最小和最大触摸位置值以及资产持续时间的最小值和最大值(显然,从零到视频的长度),然后应用以下公式将触摸位置转换为搜索时间:
// 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]; }}
我剔除了显示速率的标签,以及在您擦洗时出现的播放图标,并根据您平移视频的速度或速度来更改尺寸.虽然您没有要求,但如果您需要,请问.
哦,“times-two”因子旨在为发送给委托的setRate方法的平移手势值添加加速度曲线.您可以使用任何公式,甚至是实际曲线,如pow(nlx,2.0)或其他……
总结以上是内存溢出为你收集整理的ios – Pan寻求AVPlayer全部内容,希望文章能够帮你解决ios – Pan寻求AVPlayer所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)