问题
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