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

Posted

技术标签:

【中文标题】通过在 UISlider 中选择点来修剪音频文件【英文标题】:Trim the audiofile by selecting point in UISlider 【发布时间】:2013-09-04 07:34:18 【问题描述】:

我正在开发一个音频播放器,我需要在其中显示正在播放的音频的进度。我还需要通过选择我标记的点来修剪音频。

谢谢,

文卡特斯瓦兰

【问题讨论】:

【参考方案1】:

我终于找到了解决办法

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];

【讨论】:

以上是关于通过在 UISlider 中选择点来修剪音频文件的主要内容,如果未能解决你的问题,请参考以下文章

在 Node.js 中修剪和连接音频文件

如何使 UISlider 匹配音频进度

如何修剪音频数据?

无法使用 AVAssetExportSession 修剪音频文件

如何在颤动中制作音频修剪小部件

音频中的淡入淡出效果通过在ios中使用AVAssetExportSession