N
N
nkChehov2015-06-01 05:07:52
Objective-C
nkChehov, 2015-06-01 05:07:52

Play sound, Objective C?

Hello.
We have a void mdata array of 2048 bytes (hopefully a familiar situation), and this array needs to be reproduced.
We try AVAudioPlayer, the documentation tries to convince us that this object can be initialized using NSData, but it always comes out nill.
https://developer.apple.com/library/ios/documentat...
Here is our brave example:

AudioBufferList audioBufferList;
        NSMutableData *data = [[NSMutableData alloc] init];
        CMBlockBufferRef blockBuffer;
        CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &blockBuffer);
        
        for( int y=0; y< audioBufferList.mNumberBuffers; y++ ){
            
            AudioBuffer audioBuffer = audioBufferList.mBuffers[y];
            //Byte *frame = (Byte*)audioBuffer.mData;
            
            [data appendBytes:audioBuffer.mData length:audioBuffer.mDataByteSize];
            
        }
        
        CFRelease(blockBuffer);
        
        NSError *err;
        AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:data error:&err];
        NSLog(@"%@", err);
        [player play];

Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question