tags:

views:

13

answers:

1

I want to play the AAC which comes from a service .like mp3.But It can not be played.anyone can help me.

A: 

I play the AAC ,like this:

void IRPropertyCallback(void *in, AudioFileStreamID inAudioFileStream, AudioFileStreamPropertyID inPropertyID, UInt32 *ioFlags) { NSLog(@"property 解析"); NSLog(@"inPropertyID %x",inPropertyID); CInteractiveRadio *radio = stcast_(in); AudioStreamBasicDescription dataFormat; AudioQueueRef queue;

if (inPropertyID == kAudioFileStreamProperty_FileFormat)
{
    NSLog(@"kAudioFileStreamProperty_FileFormat");
    UInt32 fileFormatSize;
    UInt32 fileFormatValue;
    AudioFileStreamGetProperty(inAudioFileStream, inPropertyID, &fileFormatSize, &fileFormatValue);
    NSLog(@"FileFormat %x = %x",inPropertyID,fileFormatValue);
}


switch(inPropertyID) 
{
    case kAudioFileStreamProperty_DataFormat:
    {
        NSLog(@"Got data format\n");
        UInt32 len = sizeof(dataFormat);
        AudioFileStreamGetProperty(inAudioFileStream, inPropertyID, &len, &dataFormat);
        radio.dataFormat = dataFormat;
    }
        break;

    case kAudioFileStreamProperty_ReadyToProducePackets:
    {
        NSLog(@"Ready to produce packets");
        dataFormat = radio.dataFormat;
        OSStatus error = AudioQueueNewOutput(&dataFormat, OutputCallback, radio, NULL, 
                                             kCFRunLoopCommonModes, 0, &queue);

        if(error) 
        {
            NSLog(@"Unable to create audio queue!\n");
        } 
        else 
        {
            radio.queue = queue;
        }

        [radio Play];
    }
        break;
}

}

OSStatus error = AudioFileStreamParseBytes(parser, [receivedData length], [receivedData bytes], 0);

But I couldn't get the properties.Just only kAudioFileStreamProperty_FileFormat。When the program get the kAudioFileStreamProperty_FileFormat propertyID.then There is a error. the error show that :kAudioFileStreamError_NotOptimized

why? Please help me.