-1

我的 iOS 基础 SDK 是 8.1。dispatch_get_main_queue当我在 8.1 模拟器上运行时工作正常。但是,当我在 7.1 模拟器上运行它时,它不会被调用。我注意到它dispatch_get_main_queue已在 iOS 8.0 及更高版本中重新实现。

我怎么解决这个问题?更改基本 SDK 还是什么?

我的代码

    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];
        });
    }];
}
4

1 回答 1

0

最后我想通了。presetName 需要是 AVAssetExportPresetPassthrough 以便它在 iOS 7 模拟器上正常工作。我真的不知道为什么,但感谢@Kai 和@Rob 的回复。

于 2014-11-29T02:41:13.280 回答