title: Audio Toolbox playing an mp3 file (iOS)
body: <p>I've tried to get an mp3 file played with Audio Toolbox and Audio Queues, but whatever I try, I don't get anything played (neither in the simulator nor on the device). When I run it in the simulator it tells me: </p>
  
  <p>"Prime failed (-66674); will stop (0/0 frames)",</p>
  
  <p>so I think there is a basic mistake somewhere, maybe in the AudioEnqueueBuffer function, because there seems to be nothing in the queue afterwards. When I ask for the status, I always get 0 back.</p>
  
  <p>I'm sorry that I have posted so much code, but I'm just not sure where the mistake is.</p>
  
  <p>Please help me.</p>
  
  <pre><code>- (void)startPlayback{
  
   NSString *fileString = [[NSBundle mainBundle] pathForResource:@"musik" ofType:@"mp3"];
  
   const char *filePathAsCString = [fileString UTF8String];
  
   CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)filePathAsCString, strlen(filePathAsCString), false);
  
      playState.currentPacket = 0;
  
      playState.dataFormat-&gt;mSampleRate = kAudioStreamAnyRate;
      playState.dataFormat-&gt;mFormatID = kAudioFormatMPEGLayer3;
      playState.dataFormat-&gt;mFramesPerPacket = 0;
      playState.dataFormat-&gt;mChannelsPerFrame = 2;
      playState.dataFormat-&gt;mBytesPerFrame = 0;
      playState.dataFormat-&gt;mBytesPerPacket = 0;
      playState.dataFormat-&gt;mBitsPerChannel = 0;
      playState.dataFormat-&gt;mReserved = 0;
      playState.dataFormat-&gt;mFormatFlags = 0;;
  
      OSStatus status;
  
      status = AudioFileOpenURL(fileURL, kAudioFileReadPermission, kAudioFileMP3Type, &amp;playState.audioFile);
  
      if(status == 0)
      {
          status = AudioQueueNewOutput(
            &amp;playState.dataFormat,
            MyAudioOutputCallback,
            &amp;playState,
            CFRunLoopGetCurrent(),
            0,
            0,
            &amp;playState.queue);
  
          if(status == 0)
          {
              playState.playing = true;
              for(int i = 0; i &lt; 3 &amp;&amp; playState.playing; i++)
              {
                  if(playState.playing)
                  {
                      AudioQueueAllocateBufferWithPacketDescriptions(playState.queue, 64000, sizeof(AudioStreamPacketDescription)*75, &amp;playState.buffers[i]);
                      MyAudioOutputCallback(&amp;playState, playState.queue, playState.buffers[i]);
                  }
              }
  
              if(playState.playing)
              {
                  status = AudioQueueStart(playState.queue, NULL);
                  if(status == 0)
                  {
                      NSLog(@"Playing");
                  }
              }
          }        
      }
  
      if(status != 0)
      {
          NSLog(@"Play failed");
      }
  }
  </code></pre>
  
  <p>And here the Callback function:</p>
  
  <pre><code>void MyAudioOutputCallback( void *inUserData,
         AudioQueueRef outAQ,
         AudioQueueBufferRef outBuffer)
  {
      PlayState *playState= (PlayState *)inUserData;
  
      UInt32 bytesRead;
      UInt32 numPackets = 75;
  
      OSStatus status;
      status = AudioFileReadPackets(playState-&gt;audioFile, false, &amp;bytesRead, outBuffer-&gt;mPacketDescriptions, playState-&gt;currentPacket, &amp;numPackets, outBuffer-&gt;mAudioData);
  
      if(numPackets)
      {
          outBuffer-&gt;mAudioDataByteSize = bytesRead;
    outBuffer-&gt;mPacketDescriptionCount = numPackets;
          status = AudioQueueEnqueueBuffer(
             playState-&gt;queue,
             outBuffer,
             0,
             0);
  
    NSLog(@"EnqueueStatus: %d", status);
          playState-&gt;currentPacket += numPackets;
  
      }
  
  }
  </code></pre>