我想剪裁并导出我的.caf文件 我的代码是:
CMTime startTime = CMTimeMakeWithSeconds(self.audioFile.totalDuration * self.startSelectionPositionValue, NSEC_PER_SEC);
CMTime endTime = CMTimeMakeWithSeconds(self.audioFile.totalDuration * self.endSelectionPositionValue, NSEC_PER_SEC);
float startTimeInSeconds = CMTimeGetSeconds(startTime);
float endTimeInSeconds = CMTimeGetSeconds(endTime);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, endTime);
float duration = CMTimeGetSeconds(exportTimeRange.duration);
例如。我想修剪0到15秒。
startTimeInSeconds
打印0. endTimeInSeconds
打印15. exportTimeRange.duration
打印15.但结果我的文件长度为15.07。
出口商代码:
AVAssetExportSession *exporter = [AVAssetExportSession exportSessionWithAsset:sampleAsset presetName:AVAssetExportPresetAppleM4A];
exporter.outputFileType = AVFileTypeAppleM4A;
exporter.outputURL = exportUrl;
exporter.timeRange = exportTimeRange;
exporter.audioMix = audioMix;
[exporter exportAsynchronouslyWithCompletionHandler:^(void) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:NO];
switch (exporter.status) {
case AVAssetExportSessionStatusCompleted: {
// My completion code is there
break;
}
default:
break;
}
});
}];
提前致谢:)