【问题标题】:IOS trim video with range slider带有范围滑块的 IOS 修剪视频
【发布时间】:2014-02-13 19:17:21
【问题描述】:

我正在使用范围滑块来修剪正在运行的视频。但我无法将视频停止到特定时间。这是我正在使用的以下代码:

- (void)videoRange:(SAVideoRangeSlider *)videoRange didChangeLeftPosition:   (CGFloat)leftPosition rightPosition:(CGFloat)rightPosition
{
    self.startTime = leftPosition;
    self.stopTime = rightPosition;
    [self.movieController stop];

    MPMoviePlayerController *player = self.movieController;
    [player stop];
    [player setCurrentPlaybackTime:self.startTime];
    [player setEndPlaybackTime:self.stopTime];
    [player play];

}  

setCurrentPlaybackTime 有效,但“setEndPlaybackTime”无效。 请帮助我推进我的项目工作。 谢谢, 罗汉

【问题讨论】:

  • 我正在从事完全相同的项目。

标签: ios video slider


【解决方案1】:

我不记得我的范围滑块在哪里得到的,但这个可能更好https://github.com/muZZkat/NMRangeSlider

我拥有的那个可以很容易地为您提供一系列值。这是一些代码。 min 用于第一个滑块值,max 用于第二个滑块值。

.h

AVAssetExportSession *exportSession;
float max;
float min;

.m

- (void)trimVideo:(NSString *)outputURL assetObject:(AVAsset *)asset
{

@try
{
    exportSession = [[AVAssetExportSession alloc]initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];

    exportSession.outputURL = [NSURL fileURLWithPath:outputURL];

    exportSession.outputFileType = AVFileTypeQuickTimeMovie;

    CMTime start = CMTimeMakeWithSeconds(min, 1);

    CMTime duration = CMTimeMakeWithSeconds((max - min), 1);

    CMTimeRange range = CMTimeRangeMake(start, duration);

    exportSession.timeRange = range;

    exportSession.outputFileType = AVFileTypeQuickTimeMovie;

    [self checkExportSessionStatus:exportSession];

    exportSession = nil;

}
@catch (NSException * e)
{
    NSLog(@"Exception Name:%@ Reason:%@",[e name],[e reason]);
}
}

- (void)checkExportSessionStatus:(AVAssetExportSession *)exportSession
{


[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
 {

     switch ([exportSession status])
     {
         case AVAssetExportSessionStatusCompleted:
         {

                 [[[UIAlertView alloc] initWithTitle:@"Video Trimmed"
                                             message:@"Your trimmed video has been sent to your finished videos."
                                            delegate:nil
                                   cancelButtonTitle:@"Ok"
                                   otherButtonTitles:nil] show];
                 // dismiss progress bar or i use the SVProgress framework [SVProgressHUD dismiss];
                  // you can save it here                 
             break;
         }
         case AVAssetExportSessionStatusFailed:
         {
             NSLog(@"Error in exporting");
             [[[UIAlertView alloc] initWithTitle:@"Export fail"
                                         message:nil
                                        delegate:nil
                               cancelButtonTitle:@"Ok"
                               otherButtonTitles:nil] show];
         }
             break;

         default:
         {
             break;
         }

     }
 }];
 }

我希望这会有所帮助。您需要做的就是将各个部分放在一起。您可以从这里获取 SVProgress:https://github.com/TransitApp/SVProgressHUD

【讨论】:

    【解决方案2】:

    我之前遇到过这个问题,为此做了一个快速的包

    只需在您的 xcode 中单击

    文件 -> swift 包 -> 添加包 url

    复制粘贴此网址https://github.com/madadoux/DUTrimVideoView

    它有一个视图模型,你可以自己制作,将它传递给初始化器

    示例

    class ViewController: UIViewController,VideoTrimViewDelegate {
    func rangeSliderValueChanged(trimView: DUTrimVideoView, rangeSlider: DURangeSlider) {
        
    }
    
    func add() {
        let url = URL(fileURLWithPath:  Bundle.main.path(forResource: "video", ofType: "mp4")!)
        let trimView = DUTrimVideoView(asset: AVAsset(url: url), frame: CGRect(x: 20, y: 200, width: self.view.frame.width-40, height: 100))
        trimView.delegate = self
        let rangeSlider = trimView.rangeSlider!
        rangeSlider.leftThumbImage = UIImage(named: "trim-right")
        rangeSlider.rightThumbImage = UIImage(named: "trim-left")
        rangeSlider.thumbWidth = 30
        rangeSlider.thumbHeight = 30
        
        self.view.addSubview(trimView)
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let btn = UIButton(type: .infoLight, primaryAction: UIAction(handler: { (a) in
            self.view.subviews.filter({$0 is DUTrimVideoView }).first?.removeFromSuperview()
            
            self.add()
        }))
        btn.frame = CGRect(origin: .zero, size: CGSize(width: 50, height: 50))
        btn.center = self.view.center
        self.view.addSubview(btn)
    }
    

    }

    希望回答了你的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      • 2017-04-28
      • 2013-02-19
      • 2023-03-22
      • 1970-01-01
      相关资源
      最近更新 更多