title: Export session error - When using AVAudioPlayer for mp3 files
body: <p>In my app I can access the device music library, and when you select a song, it loads, however, it no longer works, and I am constantly met with the error 'export session error'
  Then the app just hangs with the spinning loading bar forever until I close the app.</p>
  <p>Select music AssetUrl = ipod-library://item/item.mp3?id=2023536838012570661
  export session error</p>
  <p>The files that I believe are troublesome are .mp3 files;
  If I use .m4a files, it seems to work fine - so is there a way to block mp3 files from appearing in the mediapicker? Or at least an alert to show the user they can't use them if they try to select an mp3 file?</p>
  <p>Here is the code;</p>
  <p>Picker code;</p>
  <pre><code>- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
  {
      dispatch_async(dispatch_get_main_queue(), ^{
      // Dismiss the media item picker.
          
          
          
      [self dismissViewControllerAnimated:YES completion:nil];
      
      if ([mediaItemCollection count] &lt; 1) {
          return;
      }
      [selectedItem release];
      selectedItem = [[[mediaItemCollection items] objectAtIndex:0] retain];
      NSURL* filePath = [selectedItem valueForProperty: MPMediaItemPropertyAssetURL];
          
      NSLog(@&quot;Select music AssetUrl = %@&quot;, filePath);
      });
  }
  
  
  - (void)exportAssetAsSourceFormat:(MPMediaItem *)item {
      
      dispatch_async(dispatch_get_main_queue(), ^{
      
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
  
      NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; //MPMediaItemPropertyAssetURL
      if (assetURL == nil)
      {
          NSLog(@&quot;assetURL is null&quot;);
          [pool release];
          return;
      }
      AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
      
      // JP
      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-&gt;mFormatID;
      
      NSString *fileType = nil;
      NSString *ex = nil;
      
      switch (formatID) {
              
          case kAudioFormatLinearPCM:
          {
              UInt32 flags = audioDesc-&gt;mFormatFlags;
              if (flags &amp; kAudioFormatFlagIsBigEndian) {
                  fileType = @&quot;public.aiff-audio&quot;;
                  ex = @&quot;aif&quot;;
              } else {
                  fileType = @&quot;com.microsoft.waveform-audio&quot;;
                  ex = @&quot;wav&quot;;
              }
          }
              break;
              
          case kAudioFormatMPEGLayer3:
              fileType = @&quot;com.apple.quicktime-movie&quot;;
              ex = @&quot;mp3&quot;;
              break;
              
          case kAudioFormatMPEG4AAC:
              fileType = @&quot;com.apple.m4a-audio&quot;;
              ex = @&quot;m4a&quot;;
              break;
              
          case kAudioFormatAppleLossless:
              fileType = @&quot;com.apple.m4a-audio&quot;;
              ex = @&quot;m4a&quot;;
              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(@&quot;export session completed&quot;);
              //return YES;
              [self performSelectorOnMainThread:@selector(gotoMainView:)
                                     withObject:[EXPORT_NAME stringByAppendingPathExtension:ex]
                                  waitUntilDone:NO];
          } else {
              NSLog(@&quot;export session error&quot;);
              //return NO;
          }
          
          [exportSession release];
      }];
      
      [pool release];
          
      });
  }
  </code></pre>