0
votes

So I setup an Audio session

AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);

UInt32 audioCategory = kAudioSessionCategory_MediaPlayback; //for output audio
OSStatus tErr = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,sizeof(audioCategory),&audioCategory);

Then setup either an AudioQueue or RemoteIO setup to play back some audio straight from a file.

AudioQueueStart(mQueue, NULL);

Once my audio is playing I can see the 'Play Icon' in the status bar of my app. I next setup an AVAssetReader.

AVAssetTrack* songTrack = [songURL.tracks objectAtIndex:0];

NSDictionary* outputSettingsDict = [[NSDictionary alloc] initWithObjectsAndKeys:

                                    [NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
                                    //     [NSNumber numberWithInt:AUDIO_SAMPLE_RATE],AVSampleRateKey,  /*Not Supported*/
                                    //     [NSNumber numberWithInt: 2],AVNumberOfChannelsKey,   /*Not Supported*/

                                    [NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
                                    [NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
                                    [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
                                    [NSNumber numberWithBool:NO],AVLinearPCMIsNonInterleaved,

                                    nil];

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

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

{   
    AVAssetReaderAudioMixOutput * readaudiofile = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:(songURL.tracks) audioSettings:outputSettingsDict];
    [reader addOutput:readaudiofile];
    [readaudiofile release];
}

return reader;

and when I called [reader startReading] the Audio stops playing. In both the RemoteIO and AudioQueue case the callback stops getting called.

If I add the mixing option:

AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (UInt32), &(UInt32) {0});

Then the 'Play Icon' no longer appears when the audio after AudioQueueStart is called. I am also locked out of other features since the phone doesn't view me as the primary audio source.

Does anyone know a way I can use the AVAssetReader and still remain the Primary audio source?

1

1 Answers

0
votes

As of iOS 5 this has been fixed. It still does not work in iOS 4 or below. MixWithOthers is not needed (can be set to false) and the AudioQueue/RemoteIO will continue to receive callbacks even if an AVAssetReader is reading.