我一直試圖按照說明here序列化本地音頻文件,而不是直接將數據包送到AudioQueBuffer,我想通過藍牙/無線使用GKSession發送它。我得到一個EXC_BAD_ACCESS錯誤:EXC_BAD_ACCESS with AudioFileReadPackets
- (void)broadcastServerMusicWithSession:(GKSession *)session playerName:(NSString *)name clients: (NSArray *)clients
{
self.isServer = YES;
_session = session;
_session.available = NO;
_session.delegate = self;
[_session setDataReceiveHandler:self withContext:nil];
CFURLRef fileURL = (__bridge CFURLRef)[[NSBundle mainBundle] URLForResource:@"mozart" withExtension:@"mp3"]; // file URL
AudioFile *audioFile = [[AudioFile alloc] initWithURL:fileURL];
//no we start sending the data over
#define MAX_PACKET_COUNT 4096
SInt64 currentPacketNumber = 0;
UInt32 numBytes;
UInt32 numPacketsToRead;
AudioStreamPacketDescription packetDescriptions[MAX_PACKET_COUNT];
NSInteger bufferByteSize = 4096;
if (bufferByteSize < audioFile.maxPacketSize) bufferByteSize = audioFile.maxPacketSize;
numPacketsToRead = bufferByteSize/audioFile.maxPacketSize;
UInt32 numPackets = numPacketsToRead;
BOOL isVBR = ([audioFile audioFormatRef]->mBytesPerPacket == 0) ? YES : NO;
// this should be in a do while (numPackets < numPacketsToRead) loop..
// but i took it out just to narrow down the problem
NSMutableData *myBuffer = [[NSMutableData alloc] initWithCapacity:numPackets * audioFile.maxPacketSize];
AudioFileReadPackets (
audioFile.fileID,
NO,
&numBytes,
isVBR ? packetDescriptions : 0,
currentPacketNumber,
&numPackets,
&myBuffer
);
NSError *error;
if (![session sendDataToAllPeers:packetData withDataMode:GKSendDataReliable error:&error])
{
NSLog(@"Error sending data to clients: %@", error);
}
我知道一個事實,即它的AudioFileReadPackets調用,將其打破了代碼,因爲它運行良好,如果我評論說,有點脫離
我試着使用的Xcode 4.3做Zombies profiling,但它只是崩潰..一個有用的調試tip我雖然被破壞時的代碼崩潰,用gdb控制檯..這是我所得到的輸出錯誤代碼:
(lldb) po [$eax className] NSException
error: warning: receiver type 'unsigned int' is not 'id' or interface pointer, consider casting it to 'id'
warning: declaration does not declare anything
error: expected ';' after expression
error: 1 errors parsing expression
但我不能用它做很多..任何幫助?
堆棧跟蹤之間的區別?任何人? – 2012-08-09 10:15:28
@stackmonster堆棧跟蹤沒有幫助 – abbood 2012-08-09 10:36:28