Created
September 3, 2012 14:04
-
-
Save pita5/3609535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)_processAudio:(AVURLAsset *)audioAsset | |
present:(NSString *)preset | |
handler:(void(^)(double percentComplete, NSError* error))handler | |
{ | |
NSString* tempDir = NSTemporaryDirectory(); | |
NSString* exportPath = [tempDir stringByAppendingPathComponent:[NSString randomString]]; | |
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) | |
{ | |
[[NSFileManager defaultManager] removeItemAtPath:exportPath | |
error:nil]; | |
} | |
NSURL* exportURL = [NSURL fileURLWithPath:exportPath]; | |
AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset:audioAsset presetName:preset]; | |
exportSession.outputURL = exportURL; | |
exportSession.shouldOptimizeForNetworkUse = YES; | |
exportSession.outputFileType = AVFileTypeAppleM4V; | |
__weak PLGYouTubeUploader* wself = self; | |
NSTimer* progressTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 | |
block:^{ | |
switch (exportSession.status) | |
{ | |
case AVAssetExportSessionStatusFailed: | |
[wself _failAudioProcessing:handler]; | |
break; | |
case AVAssetExportSessionStatusCancelled: | |
[wself _failAudioProcessing:handler]; | |
break; | |
default: | |
handler(exportSession.progress, nil); | |
break; | |
} | |
} | |
repeats:YES]; | |
[exportSession exportAsynchronouslyWithCompletionHandler:^{ | |
[progressTimer invalidate]; | |
if (exportSession.status == AVAssetExportSessionStatusCompleted) | |
{ | |
NSString* path = exportSession.outputURL.path; | |
} | |
else | |
{ | |
SHOW_ALERT_ERROR(@"") | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment