1

我正在尝试从 ipod 库中导出音频文件。如果起始值为 0.0,则导出工作正常。如果起始值大于 0.0,则音频文件为空。状态已完成,但文件大小为 0 kb 。有人可以给我一个解决方案还是这是另一个 Apple 错误?

float vocalStartMarker = startValue;
float vocalEndMarker = endValue;

NSURL *audioFileInput = url;

NSString *voicePath = [path stringByAppendingPathComponent:@"audio"];

NSString *uniquePath = [mainViewController uniqueFilename:voicePath withExtension:@"caf"];

NSURL *audioFileOutput = [NSURL fileURLWithPath:uniquePath];



if (!audioFileInput || !audioFileOutput)
{
    return NO;
}

[[NSFileManager defaultManager] removeItemAtURL:audioFileOutput error:NULL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:audioFileInput options:nil];

AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset
                                                                        presetName:AVAssetExportPresetAppleM4A];

if (exportSession == nil)
{
    return NO;
}

CMTime startTime = CMTimeMake((int)(floor(vocalStartMarker * 100)), 100);
CMTime stopTime = CMTimeMake((int)(ceil(vocalEndMarker * 100)), 100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime);

exportSession.outputURL = audioFileOutput;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.timeRange = exportTimeRange;

[exportSession exportAsynchronouslyWithCompletionHandler:^
 {
     if (AVAssetExportSessionStatusCompleted == exportSession.status)
     {
         NSLog(@"it worked:%@",uniquePath);
         // It worked!

         [music replaceObjectAtIndex:currentPage withObject:uniquePath];


     }
     else if (AVAssetExportSessionStatusFailed == exportSession.status)
     {
         NSLog(@"it failed");
         // It failed...
     }
 }];

[self.popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;

return YES;
4

0 回答 0