实现播放器的断点播放有两个思路:
1.自定义进度条(使用UIView绘制)
2.在UISlider基础上实现断点播放
在这里简单介绍下用第2中思路是怎么实现的
实现思路:
扩展一个UISlider子类,在子类方法中重写开始触摸代理方法
-(void)touchesBegan:(NSSet <UITouch *> *)touches withEvent:(UIEvent *)event
代码具体实现:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
CGRect trackRect = [self trackRectForBounds: [self bounds]];
float value = [self minimumValue] + ([[touches anyObject] locationInView: self].x - t.origin.x - 4.0) * (([self maximumValue]-[self minimumValue]) / (trackRect.size.width - 8.0));
[self setValue:value];
[super touchesBegan:touches withEvent:event];
double current = value * [AudioPlayer shareInstance].player.duration;
[[AudioPlayer shareInstance].player setCurrentTime:current];
}
网友评论