title: in iOS Entended Audio File Services and Streaming Audio
body: <p>First Export from iPod Library m4a file.<br>
  Second Convert to AAC using Extended Audio File Services<br>
  Third transport the music file to other iPhone.<br>
  Fourth Streaming audio using Audio File Stream Services<br>
  It usually works.But the audio file playtime over about 5minitues it can't work.<br>
  However,I try 15minitues audio file mp3 and aac into my project.and streaming it.it worked.<br>
  So,I think the cause is Convert Step. Something wrong with my code ?<br>
  Could you give me some advices ?</p>
  
  <pre><code>-(void)convertFrom:(NSURL*)fromURL
           toURL:(NSURL*)toURL{
  ExtAudioFileRef infile,outfile;
  OSStatus err;
  //ExtAudioFileの作成
  err = ExtAudioFileOpenURL((__bridge CFURLRef)fromURL, &amp;infile);
  checkError(err,"ExtAudioFileOpenURL");
  
  AudioStreamBasicDescription inputFormat;
  AudioStreamBasicDescription outputFormat;
  AVAudioSession * audiosession =[AVAudioSession sharedInstance];
  
  [audiosession setActive:YES error:nil];
  [audiosession setCategory:AVAudioSessionCategoryAudioProcessing error:nil];
  
  //変換するフォーマット(AAC)
  memset(&amp;outputFormat, 0, sizeof(AudioStreamBasicDescription));
  outputFormat.mSampleRate       = 44100.0;
  outputFormat.mFormatID         = kAudioFormatMPEG4AAC;//AAC
  outputFormat.mChannelsPerFrame = 1;
  
  UInt32 size = sizeof(AudioStreamBasicDescription);
  AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
                         0, NULL,
                         &amp;size,
                         &amp;outputFormat);//変換後のフォーマット
  
  
  err = ExtAudioFileGetProperty(infile,//変換前のファイルのプロパティを取得
                                kExtAudioFileProperty_FileDataFormat,
                                &amp;size,
                                &amp;inputFormat);
  checkError(err,"ExtAudioFileGetProperty");
  
  //リニアPCM以外からの変換であれば、リニアPCMとして読み込む
  if(inputFormat.mFormatID != kAudioFormatLinearPCM){
      //一旦変換するフォーマット(リニアPCM Little Endian)
      AudioStreamBasicDescription linearPCMFormat;
      linearPCMFormat.mSampleRate         = outputFormat.mSampleRate;
      linearPCMFormat.mFormatID           = kAudioFormatLinearPCM;
      linearPCMFormat.mFormatFlags        =  kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
      linearPCMFormat.mFramesPerPacket    = 1;
      linearPCMFormat.mChannelsPerFrame   = outputFormat.mChannelsPerFrame;
      linearPCMFormat.mBitsPerChannel     = 16;
      linearPCMFormat.mBytesPerPacket     = 2 * outputFormat.mChannelsPerFrame;
      linearPCMFormat.mBytesPerFrame      = 2 * outputFormat.mChannelsPerFrame;
      linearPCMFormat.mReserved           = 0;
  
      //読み出すフォーマットをリニアPCMにする(中間フォーマット)
      inputFormat = linearPCMFormat;
  }
  //読み込むフォーマットを設定
  //必ずlinearPCMで読み出される
  err = ExtAudioFileSetProperty(infile,
                                kExtAudioFileProperty_ClientDataFormat,
                                sizeof(AudioStreamBasicDescription),
                                &amp;inputFormat);
  checkError(err,"ExtAudioFileSetProperty");
  
  
  
  err = ExtAudioFileCreateWithURL((__bridge CFURLRef)toURL,
                                  kAudioFileM4AType, //AAC
                                  &amp;outputFormat,
                                  NULL,
                                  kAudioFileFlags_EraseFile,
                                  &amp;outfile);
  checkError(err,"ExtAudioFileCreateWithURL");
  
  //書き込むファイルに、入力がリニアPCMであることを設定
  err = ExtAudioFileSetProperty(outfile,
                                kExtAudioFileProperty_ClientDataFormat,
                                sizeof(AudioStreamBasicDescription),
                                &amp;inputFormat);
  checkError(err,"kExtAudioFileProperty_ClientDataFormat");
  
  //読み込み位置を0に移動
  err = ExtAudioFileSeek(infile, 0);
  checkError(err,"ExtAudioFileSeek");
  
  //一度に読み込むフレーム数
  UInt32 readFrameSize = 1024;
  
  //読み込むバッファ領域を確保
  UInt32 bufferByteSize = sizeof(char) * readFrameSize * inputFormat.mBytesPerPacket;
  char *buffer = malloc(bufferByteSize);
  
  //AudioBufferListの作成
  AudioBufferList audioBufferList;
  audioBufferList.mNumberBuffers = 1;
  audioBufferList.mBuffers[0].mNumberChannels = inputFormat.mChannelsPerFrame;
  audioBufferList.mBuffers[0].mDataByteSize = bufferByteSize;
  audioBufferList.mBuffers[0].mData = buffer;
  
  while(1){
      UInt32 numPacketToRead = readFrameSize;
      err = ExtAudioFileRead(infile, &amp;numPacketToRead, &amp;audioBufferList);
      checkError(err,"ExtAudioFileRead");
  
      //読み込むフレームが無くなったら終了する
      if(numPacketToRead == 0){
          NSLog(@"変換完了");
          break;
  
      }
      err = ExtAudioFileWrite(outfile,
                              numPacketToRead,
                              &amp;audioBufferList);
      checkError(err,"ExtAudioFileWrite");
  }
  
  ExtAudioFileDispose(infile);
  ExtAudioFileDispose(outfile);
  free(buffer);
  void propertyListenerProc(
                        void *                            inClientData,
                        AudioFileStreamID             inAudioFileStream,
                        AudioFileStreamPropertyID     inPropertyID,
                        UInt32 *                      ioFlags
                        ){
  
  StreamInfo* streamInfo = (StreamInfo*)inClientData;
  OSStatus err;
  NSLog(@"property%u",(unsigned int)inPropertyID);
  </code></pre>