I'm working with AVFoundation using audio only - i.e. no video - and trying to join several AVCompositions together, one after the other, to end up with one single AVComposition.
Example case: just two AVCompositions. Each of them plays fine by creating an AVPlayer thus:
_player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:comp]]
where comp is an instance of AVMutableComposition. (Incidentally, it's worth noting that _player has to be an ivar otherwise ARC prematurely releases it before it plays - took a while to track that one down.)
That's good - executing
[_player play]
results in comp being played back successfully.
However, this fails:
(self.segments is an NSMutableArray containing elements that are a custom subclass of AVMutableComposition)
AVMutableComposition *comp = [AVMutableComposition composition];
NSError *err;
for (AVMutableComposition* c in self.segments) {
    [comp insertTimeRange:CMTimeRangeMake(kCMTimeZero, segment.duration)      
                  ofAsset:segment atTime:comp.duration error:&err];
    DLog(@"Error was %@", segment, err);
}
For every element of self.segments when this code executes, I get this error when invoking the insertTimeRange:::: method:
Error was Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not
be completed" UserInfo=0x14e8e7f0 {NSLocalizedDescription=The operation could not be 
completed, NSUnderlyingError=0x14d7f580 "The operation couldn’t be completed. (OSStatus 
error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780)}
I can't find any information about what this error indicates - seems to be just a catch-all - and I can't see what I'm doing wrong. Any ideas?