@@ -269,22 +269,23 @@ void BackgroundTrackMgr2::QueueCallback( void * inUserData, AudioQueueRef inAQ,
269
269
OSStatus result = noErr ;
270
270
BackgroundTrackMgr2 *THIS = (BackgroundTrackMgr2*)inUserData;
271
271
UInt32 nPackets = 0 ;
272
+ UInt32 ioNumBytes;
272
273
// loop the current buffer if the following:
273
274
// 1. file was loaded into the buffer previously
274
275
// 2. only one file in the queue
275
276
// 3. we have not been told to stop at playlist completion
276
277
if ((CurFileInfo->mFileDataInQueue ) && (!THIS->mStopAtEnd )) {
277
278
nPackets = THIS->mNumPacketsToRead ;
278
279
} else {
279
- UInt32 numBytes;
280
280
while (nPackets == 0 ) {
281
281
// if loadAtOnce, get all packets in the file, otherwise ~.5 seconds of data
282
- nPackets = THIS->mNumPacketsToRead ;
283
- result = AudioFileReadPacketData (CurFileInfo->mAFID , false , &numBytes, THIS->mPacketDescs , THIS->mCurrentPacket , &nPackets, inCompleteAQBuffer->mAudioData );
282
+ nPackets = THIS->mNumPacketsToRead ;
283
+ ioNumBytes = kAudioFilePropertyMaximumPacketSize * nPackets;
284
+
285
+ result = AudioFileReadPacketData (CurFileInfo->mAFID , false , &ioNumBytes, THIS->mPacketDescs , THIS->mCurrentPacket , &nPackets, inCompleteAQBuffer->mAudioData );
284
286
AssertNoError (" Error reading file data" , end);
285
287
286
- inCompleteAQBuffer->mAudioDataByteSize = numBytes;
287
-
288
+ inCompleteAQBuffer->mAudioDataByteSize = ioNumBytes;
288
289
if (nPackets == 0 ) { // no packets were read, this file has ended.
289
290
if (CurFileInfo->mLoadAtOnce ) {
290
291
CurFileInfo->mFileDataInQueue = true ;
0 commit comments