在运行iOS7的iPhone或iPad设备上从用户库中选择一首歌时,我的应用程序崩溃了
它停在的行是
FourCharCode formatID = audioDesc->mFormatID;
使用EXC_BAD_ACCESS代码
尝试检查控制台以获取更多信息,这是它提到的最后一步;
appMake [8392:60b]选择音乐AssetUrl =(null)
以下代码用于导出会话部分;
- (void)exportAssetAsSourceFormat:(MPMediaItem *)item {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:songAsset
presetName:AVAssetExportPresetPassthrough];
NSArray *tracks = [songAsset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack *track = [tracks objectAtIndex:0];
id desc = [track.formatDescriptions objectAtIndex:0];
const AudioStreamBasicDescription *audioDesc = CMAudioFormatDescriptionGetStreamBasicDescription((CMAudioFormatDescriptionRef)desc);
FourCharCode formatID = audioDesc->mFormatID;
NSString *fileType = nil;
NSString *ex = nil;
switch (formatID) {
case kAudioFormatLinearPCM:
{
UInt32 flags = audioDesc->mFormatFlags;
if (flags & kAudioFormatFlagIsBigEndian) {
fileType = @"public.aiff-audio";
ex = @"aif";
} else {
fileType = @"com.microsoft.waveform-audio";
ex = @"wav";
}
}
break;
case kAudioFormatMPEGLayer3:
fileType = @"com.apple.quicktime-movie";
ex = @"mp3";
break;
case kAudioFormatMPEG4AAC:
fileType = @"com.apple.m4a-audio";
ex = @"m4a";
break;
case kAudioFormatAppleLossless:
fileType = @"com.apple.m4a-audio";
ex = @"m4a";
break;
default:
break;
}
exportSession.outputFileType = fileType;
NSString *exportPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:[EXPORT_NAME stringByAppendingPathExtension:ex]] retain];
if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) {
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
exportSession.outputURL = [NSURL fileURLWithPath:exportPath];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
NSLog(@"export session completed");
//return YES;
[self performSelectorOnMainThread:@selector(gotoMainView:)
withObject:[EXPORT_NAME stringByAppendingPathExtension:ex]
waitUntilDone:NO];
} else {
NSLog(@"export session error");
//return NO;
}
[exportSession release];
}];
[pool release];
}
媒体选择器代码;
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
// Dismiss the media item picker.
[self dismissModalViewControllerAnimated: YES];
if ([mediaItemCollection count] < 1) {
return;
}
[selectedItem release];
selectedItem = [[[mediaItemCollection items] objectAtIndex:0] retain];
NSURL* filePath = [selectedItem valueForProperty: MPMediaItemPropertyAssetURL];
NSLog(@"Select music AssetUrl = %@", filePath);
[viewLoading setHidden:NO];
[self UnloadSound];
[NSThread detachNewThreadSelector:@selector(exportAssetAsSourceFormat:) toTarget:self withObject:selectedItem];
}