2014-01-23 68 views
1

我正在使用範圍滑塊來修剪正在運行的視頻。但我無法將視頻停止在特定時間。這是下面的代碼,我使用:帶有範圍滑塊的IOS修剪視頻

- (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」是行不通的。 請幫我完成我的項目工作。 謝謝, 羅漢

+0

我正在研究完全相同的項目。 – iOSAaronDavid

回答

0

我不記得在那裏我得到了我的範圍滑塊,但是這一次可能會更好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