通过在UISlider中选择点来修剪音频文件

时间:2013-09-04 07:34:18

标签: avaudioplayer audio-recording uislider uiprogressbar

我正在使用Audioplayer,我需要显示正在播放的音频的进度。此外,我需要通过选择我标记的点来修剪音频。

Below is the image i have attached

谢谢,

Venkateshwaran

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案

enter code here 

    UISlider *sliderProgress = [[UISlider alloc] initWithFrame:CGRectMake(135, 165, 260, 28)];
    sliderProgress.maximumValue = self.player.duration;
    [sliderProgress addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
    [self setProgressSlider:sliderProgress];
    [self addSubview:progressSlider];
    [sliderProgress release];

    _leftThumbView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 56, 35)];
    _leftThumbView.image = [UIImage imageNamed:@"top.png"];
    _leftThumbView.contentMode = UIViewContentModeLeft;
    _leftThumbView.userInteractionEnabled = YES;
    _leftThumbView.clipsToBounds = YES;
    [progressSlider addSubview:_leftThumbView];

    UIPanGestureRecognizer *leftPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftPan:)];
    [_leftThumbView addGestureRecognizer:leftPan];

    _rightThumbView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 56, 35)];
    _rightThumbView.image = [UIImage imageNamed:@"bottom.png"];
    _rightThumbView.contentMode = UIViewContentModeRight;
    _rightThumbView.userInteractionEnabled = YES;
    _rightThumbView.clipsToBounds = YES;
    [progressSlider addSubview:_rightThumbView];

    UIPanGestureRecognizer *rightPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightPan:)];
    [_rightThumbView addGestureRecognizer:rightPan];

      - (void)handleLeftPan:(UIPanGestureRecognizer *)gesture
    {
        if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
          CGPoint translation = [gesture translationInView:self];
          CGFloat range = progressSlider.maximumValue - progressSlider.minimumValue;
    CGFloat availableWidth = 260 - 28;
    _leftValue += translation.x / availableWidth * range;
    if (_leftValue < 0) _leftValue = progressSlider.minimumValue;
    if (_rightValue - _leftValue < progressSlider.minimumValue) _leftValue = _rightValue - 1.0;

    [gesture setTranslation:CGPointZero inView:self];

    [self setNeedsLayout];



}

//if (gesture.state == UIGestureRecognizerStateEnded)
    //[self hidePopover:_leftPopover];

}

       - (void)handleRightPan:(UIPanGestureRecognizer *)gesture
    {
         if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
        CGPoint translation = [gesture translationInView:self];
    CGFloat range = progressSlider.maximumValue - progressSlider.minimumValue;
    CGFloat availableWidth = 260 - 28;
    _rightValue += translation.x / availableWidth * range;

    if (_rightValue > progressSlider.maximumValue) _rightValue = progressSlider.maximumValue;
    if (_rightValue - _leftValue < progressSlider.minimumValue) _rightValue = _leftValue + 1.0;

    [gesture setTranslation:CGPointZero inView:self];

    [self setNeedsLayout];

}