實現(xiàn)播放器的斷點播放有兩個思路:
1.自定義進度條(使用UIView繪制)
2.在UISlider基礎上實現(xiàn)斷點播放
在這里簡單介紹下用第2中思路是怎么實現(xiàn)的
實現(xiàn)思路:
擴展一個UISlider子類,在子類方法中重寫開始觸摸代理方法
-(void)touchesBegan:(NSSet <UITouch *> *)touches withEvent:(UIEvent *)event
代碼具體實現(xiàn):
-(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];
}