Starting an AVAssetReader stopping callbacks to a Remote I/O AudioUnit

廉价感情. 提交于 2019-12-24 10:29:39

问题


I am using an AVAssetReader to read the audio out of the iPod Library. (see here) I then take the read buffer and play it through an AudioUnit. I am trying to refractor the code to stream in the Audio as I play it out. However if an AVAssetReader is running the AudioUnit stops receiving calls to its kAudioUnitProperty_SetRenderCallback.

I have simplified my code to only play a file within the AudioUnits callback...

OSStatus UnitRenderCB(void* pRefCon, AudioUnitRenderActionFlags* flags, const AudioTimeStamp* timeStamp, UInt32 busNum, UInt32 numFrames, AudioBufferList*  pData){

    OSStatus tErr = noErr;
    MySoundStream* pS = (MySoundStream*)pRefCon;

    ExtAudioFileRead(pS->InRef, &numFrames, pData);     // Here's the MP3/WAV/etc Data loaded...

    if (numFrames <= 0){    // EOF?
        ExtAudioFileSeek(pS->InRef, 0);
        return 1;
    }

    return tErr;
}

and then I call this code and the AudioUnit stops playing, the UnitRenderCB is no longer called.

    NSError* error = nil;
    AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:songURL error:&error];

    {
        AVAssetReaderTrackOutput* output = [[AVAssetReaderTrackOutput alloc] initWithTrack:songTrack outputSettings:outputSettingsDict];
        [reader addOutput:output];
        [output release];
    }


    [reader startReading];

    [reader cancelReading];

    [reader release];

I am using the same AudioUnit setup as is listed here

Does the AVAssetReader use the AudioUnit systems? Is there no way to make them work together?


回答1:


You have to create an AudioSession and set a mixable category, described here under "Working with Music Players".

This document actually describes how to configure your AudioSession for use with the MediaPlayer framework, but it applies equally well to AVAssetReader.




回答2:


Ensure you have called 'AudioSessionInitialize' without it strange things can occur.



来源:https://stackoverflow.com/questions/6209565/starting-an-avassetreader-stopping-callbacks-to-a-remote-i-o-audiounit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!