I create a trim audio function.
select the file on iPod library and want to select some time range store in new file to draw as waveform
this is an create new file in trim function
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"cropedFile.m4a"];
NSURL *fileInput = self.globalURL;
NSURL *fileOutput = [[NSURL alloc] initFileURLWithPath:path];
NSLog(@"Output destination: %@", fileOutput);
if(!fileInput || !fileOutput) return NO;
[[NSFileManager defaultManager] removeItemAtURL:fileOutput error:nil];
AVAsset *asset = [AVAsset assetWithURL:fileInput];
NSLog(@"asset: %@", asset);
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetAppleM4A];
if(exportSession == nil) return NO;
NSLog(@"%@",exportSession);
CMTime startTime = CMTimeMake((int)(floor(beginCropMarker * 100)),100);
CMTime stopTime = CMTimeMake((int)(floor(endCropMarker * 100)), 100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime);
exportSession.outputURL = fileOutput;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.timeRange = exportTimeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
if(AVAssetExportSessionStatusCompleted == exportSession.status)
NSLog(@"Crop completed");
else if(AVAssetExportSessionStatusFailed == exportSession.status)
NSLog(@"Crop failed");
}];
when I run this an error is in draw waveform function in this line
AVAssetTrack * songTrack = [songAsset.tracks objectAtIndex:0];
with message
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
I don't know how to fix it help me please.
Aucun commentaire:
Enregistrer un commentaire