Reputation: 357
Thanks for reading my issue. :D
here is my question
i was using AVAudioRecorder to recording audio files as Vocal resources, aim to insert vocal to my video at different times. But there is an error when i insert vocal to my vocal track (AVMutableCompositionTrack),and the error msg just tell me this
Error Domain=AVFoundationErrorDomain
Code=-11800
"The operation could not be completed"
UserInfo={NSUnderlyingError=0x137104220
{Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"},
NSLocalizedFailureReason=An unknown error occurred (-12780),
NSLocalizedDescription=The operation could not be completed}
when i was inserting vocal to my vocal track,i was using the same way just like inserting music track. here is my code of insert music track
/*this is my testing code of inserting music track to my video project*/
self.musicTrack = [self.projectComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:3];
NSString *file = [[NSBundle mainBundle] pathForResource:@"Lost!" ofType:@"mp3"];
NSURL *musicURL = [NSURL fileURLWithPath:file];
AVURLAsset *music = [AVURLAsset assetWithURL:musicURL];
AVAssetTrack *musicTrack = [music tracksWithMediaType:AVMediaTypeAudio].firstObject;
NSError *err;
[self.musicTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(10, kCMTimeMaxTimescale)) ofTrack:musicTrack atTime:CMTimeMakeWithSeconds(0, kCMTimeMaxTimescale) error:&err];
[self.musicTrack insertTimeRange:CMTimeRangeMake(CMTimeMakeWithSeconds(15, kCMTimeMaxTimescale),
CMTimeMakeWithSeconds(5, kCMTimeMaxTimescale))
ofTrack:musicTrack
atTime:CMTimeMakeWithSeconds(20, kCMTimeMaxTimescale)
error:&err];
[self.musicTrack insertTimeRange:CMTimeRangeMake(CMTimeMakeWithSeconds(24, kCMTimeMaxTimescale),
CMTimeMakeWithSeconds(10, kCMTimeMaxTimescale))
ofTrack:musicTrack
atTime:CMTimeMakeWithSeconds(30, kCMTimeMaxTimescale)
error:&err];
[self.musicTrack insertTimeRange:CMTimeRangeMake(CMTimeMakeWithSeconds(0, kCMTimeMaxTimescale),
CMTimeMakeWithSeconds(10, kCMTimeMaxTimescale))
ofTrack:musicTrack
atTime:CMTimeMakeWithSeconds(45, kCMTimeMaxTimescale)
error:&err];
self.musicParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:self.musicTrack];
[self.musicParameters setVolume:.8f atTime:kCMTimeZero];
the code š was worked just fine
and here is my code of inserting vocals
self.vocalTrack = [self.projectComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:4];
self.vocalParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:self.vocalTrack];
NSError *err;
for (NSInteger i = 0; i < self.vocalResourceArray.count; i++) {
RAGE_VocalModel * vm = self.vocalResourceArray[i];
[self.vocalTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, vm.vocal_Duration) ofTrack:vm.vocal_AssetTrack atTime:vm.vocal_StartTime error:&err];
/*error caught from here*/
if (err) {
[self.vocalTrack removeTimeRange:CMTimeRangeMake(kCMTimeZero, vm.vocal_Duration)];
NSLog(@"Error during insert vocal track\nerr:%@",err);
}
}
[self.vocalParameters setVolume:1.f atTime:kCMTimeZero];
and also i was using same code inserting my video's sound to target sound track,works fine.
so i was thinking there might be an issue when i recording my audio file maybe?something error of my audio format setting maybe?
here is my audio recording setting
NSString * rec_id = [NSString stringWithFormat:@"%zd",arc4random()];
NSURL *recordingFile = [NSURL fileURLWithPath:[[TARGET_DIR stringByAppendingPathComponent:@"Records"] stringByAppendingPathComponent:[NSString stringWithFormat:@"R%@.aac",rec_id]]];
NSDictionary *setting = @{
AVFormatIDKey : @(kAudioFormatMPEG4AAC),
AVSampleRateKey : @44100,
AVNumberOfChannelsKey : @1,
AVEncoderAudioQualityKey : @(AVAudioQualityHigh),
};
and i was recording audio by using this
self.recorder = [[AVAudioRecorder alloc]initWithURL:recordingFile settings:setting error:&err];
and...well.... works fine,no error caught.
anyway,i tried to check the audio file in sandbox,it's playable[on MAC OS / Windows].
any ideas about what's going on? this issue was caught me almost 2 months,still finding solution.
Update:
is it possible due to using block? i was formatting vocalModel using block handle
š
[RAGE_VocalModel vocalModelWithURL:recorder.url withCompleteHandle:^(RAGE_VocalModel *model) {
model.vocal_StartTime = Recording_Temp_Start_Time;
Recording_Temp_Start_Time = kCMTimeZero;;
[self.vocalResourceArray addObject:model];
NSLog(@"thread = %zd",[NSThread currentThread]);
}];
that's remind me something when i was trying to insert music track,i was using enumerateByBlock to insert every source tracks to project tracks before,and caught the same error(well..possible not the exactly same,but still caught unknown error) during insert music track.
btw,music was in my app bundle for now,and vocal file is in sandbox.
i'll update my question as soon as i found more information.
UPDATE #2
it's not the block's fault ,i was tried to just using alloc-init
then setting all the properties of my vocal model.same issue at same line.
Upvotes: 2
Views: 155
Reputation: 357
here i found some solution about my issue to temporary solve this part of my issue
can not insert resource to track
what i found is ,it's might due to the audio file is not completed formatted , so i was just save the file URL in my vocal model, when i insert resource to my audio/sound/music track,i just load an temp AVURLAsset and pump out audio track,then insert to my AVMutableCompositionTrack , that's works pretty fine.
but i still believe it's might not the best solution of this issue.
wish could help.
Upvotes: 1