My iOS base SDK is 8.1. dispatch_get_main_queue
works fine when I'm running on 8.1 simulator. However when I run it on 7.1 simulator, it does not get called. I noticed that dispatch_get_main_queue
has been reimplemented in iOS 8.0 and later.
How can I solve this problem? change base SDK or what?
my code
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
// audio track
AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
//
NSError *error;
AVAsset *videoAsset = [AVAsset assetWithURL:videoURL];
[audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeAudio] firstObject]
atTime:kCMTimeZero
error:&error];
if (error) {
NSLog(@"extract audio error!");
return;
}
error = nil;
// audio path
NSString *path = [NSString stringWithFormat:@"%@newAudio.m4a", NSTemporaryDirectory()];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) {
NSLog(@"audio cannot be saved!");
}
}
// exporter
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPresetAppleM4A];
exporter.outputURL = [NSURL fileURLWithPath:path];
exporter.outputFileType = AVFileTypeAppleM4A;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^{
//NSLog(@"export status: %ld", exporter.status);
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:exporter];
});
}];
}
Finally i figured it out. The presetName need to be AVAssetExportPresetPassthrough so that it works fine on iOS 7 simulator. I don't really know why, but thank you @Kai and @Rob for your replies.