IPhone : Can not play audio in didReceiveData method

on Wednesday, April 1, 2015

My aim is to stream voice data to multiple devices using multipeer connnectivity.


I am using AVCaptureSession to access voice data from microphone using AVCaptureDevice type AVMediaTypeAudio.


In a custom AVCaptureAudioDataOutput class i am getting those audio data and want to stream that to all connected peers.



//sending data using Multipeer Connectivity

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{

// NSLog(@"---A U D I O :%@",sampleBuffer);

AudioBufferList audioBufferList;
NSMutableData *data= [NSMutableData data];
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);

for( int y=0; y< audioBufferList.mNumberBuffers; y++ ){
AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
Float32 *frame = (Float32*)audioBuffer.mData;

[data appendBytes:frame length:audioBuffer.mDataByteSize];
}

CFRelease(blockBuffer);
[_session sendData:data toPeers:_session.connectedPeers withMode:MCSessionSendDataReliable error:nil];
}


In the Receiver application I am getting all nsdata in didRecievedData delegate method in MCSessionDelegate.


But I am not getting any way to play that raw NSData in Reciever application.


0 comments:

Post a Comment