here으로 표시된 기술을 사용하여 일부 오디오 파일을 연결하려고합니다. 내 오디오 파일은 .m4a이며 Quicktime에서 정상적으로 작동하는지 확인할 수 있습니다. 여기에 내가 그들을 연결하는 사용하려고 해요 코드는 다음과 같습니다 눈치코코아 : 파일에서로드 된 AVAsset에 0 트랙이 있습니다.
[currFile.audioContent writeToFile:tempOldFilePath atomically:NO];
AVURLAsset *oldAudioAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:tempOldFilePath] options:nil];
AVURLAsset *newAudioAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:tempInputFilePath] options:nil];
NSLog(@"oldAsset num tracks = %lu",(unsigned long)oldAudioAsset.tracks.count);
NSLog(@"newAsset num tracks = %lu",(unsigned long)newAudioAsset.tracks.count);
AVAssetTrack *oldTrack = [[oldAudioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVAssetTrack *newTrack = [[newAudioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVMutableComposition *mutableComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
NSError *error=nil;
[compTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, oldTrack.timeRange.duration) ofTrack:oldTrack atTime:kCMTimeZero error:&error];
if (error) {
NSLog(@"%@",error.localizedDescription);
error=nil;
}
[compTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, newTrack.timeRange.duration) ofTrack:newTrack
atTime:oldTrack.timeRange.duration error:&error];
if (error) {
NSLog(@"%@",error.localizedDescription);
error=nil;
}
exporter = [[AVAssetExportSession alloc] initWithAsset:mutableComposition presetName:AVAssetExportPresetAppleM4A];
exporter.outputURL = [NSURL URLWithString:tempCompFilePath];
exporter.outputFileType = AVFileTypeAppleM4A;
[exporter exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"handller");
NSError *error=nil;
NSData *newData = [NSData dataWithContentsOfFile:tempCompFilePath options:0 error:&error];
NSLog(@"%lu",(unsigned long)newData.length);
if (error) {
NSLog(@"%@",error.localizedDescription);
}
currFile.audioContent = newData;
[[AppDelegate sharedDelegate] saveAction:nil];
}];
첫 번째 문제는 수출의 핸들러 메소드가 호출되지 않습니다 것입니다. 그 이유는 다음과 같습니다. URL에서 AVAssets를 생성 한 후 로그 문에 0 개의 트랙이 포함되어 있음을 알 수 있습니다. Apple의 예는 AVAssets의로드 방식을 정확하게 보여주지 않습니다.
이 방법을 얻는 방법에 대한 조언이 있으십니까?
사용하려는 OS X 버전은 무엇입니까? –