I am trying to combine 2 WAV files using AVAssetExportSession, under iOS7. I have confirmed that the files are there and do not seem corrupted or something else. These are WAV files that were taken from recordings made from the device itself, and they are relatively small files.
When it calls the exportAsync method, it immediately crashes with the "Operation Stopped" error immediately in the completion block (reason description: "Operation is not supported for this medium"). This happens in the simulator and the device itself. The following is the export code:
NSError *avError = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; AVURLAsset *tmpAsset = [[AVURLAsset alloc] initWithURL:_tmpRecordingUrl options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @YES}]; AVURLAsset *permAsset = [[AVURLAsset alloc] initWithURL:_url options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @YES}]; AVMutableComposition *composition = [AVMutableComposition composition]; [composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, permAsset.duration) ofAsset:permAsset atTime:kCMTimeZero error:&avError]; [composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, tmpAsset.duration) ofAsset:tmpAsset atTime:CMTimeMakeWithSeconds(_positionSlider.value, 1) error:&avError]; AVAssetExportSession *export = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetPassthrough]; if ([fileManager fileExistsAtPath:[_workingUrl path]]) { [fileManager removeItemAtURL:_workingUrl error:&avError]; } export.outputFileType = AVFileTypeWAVE; export.outputURL = _workingUrl; [export exportAsynchronouslyWithCompletionHandler:^(void) {
I also confirmed that "avError" never fills, so there seems to be no problem with pasting timeRanges or creating an export session. I checked the assets and they are readable, playable, and exportable (for the bool values ββon obj).
Did I miss something obvious here? This code works great with iOS6. Feel free to let me know if I need to provide additional information, and well in advance for any direction that you can offer!
EDIT No. 1 . I tried to add a tracking mechanism similar to that of this post: AVAssetExportSession - Attach 2 mp4 files to IOS , but no luck there, the same problem. Also, if you need to know, the same error occurs when I switch from WAV to CAF. This is what I get when I print supportedFileTypes when trying to use any audio format:
( "com.apple.quicktime-movie", "com.apple.m4a-audio", "public.mpeg-4", "com.apple.m4v-video", "public.3gpp", "org.3gpp.adaptive-multi-rate-audio", "com.microsoft.waveform-audio", "public.aiff-audio", "public.aifc-audio", "com.apple.coreaudio-format" )
Since the audio formats are there, and the exporter returns YES for both exported, reproducible, and readable resources, I see no reason why it could fail with such an error.
EDIT No. 2 . More info - even when I split the code to a minimal level, just by creating an AVAsset from NSURL and then loading it into the AVAssetExportSession using the interrupt preset, it still just fails in iOS7. There must be something here that I do not see here.
I tested this MOST code with video files (mp4) and it works fine in iOS7. I took the same code and adjusted it for the WAV, CAF, and M4A files, and it worked every time with "Operation is not supported for this medium." mistake.
Is this a bug in the Apple code, or can we even do this using audio files with iOS7? I donβt see anything about this in the Apple AV Foundation section of the What's New in iOS7 document, but it works fine in iOS6. I'm probably going to get Apple into this.