I’m updating an earlier app that used setDelegate
to configure AVAudioSession
to play audio. I’m at the stage of hooking up the new UI to drive the audio but I get no sound. When I updated the app a year ago, Xcode notified that setDelegate: was deprecated
but I was able to get audio by commenting out
[[AVAudioSession sharedInstance] setDelegate:player];
and replacing it with
[[AVAudioSession sharedInstance] setActive:YES error:nil];
EDIT: My session uses setCategory:AVAudioSessionCategoryPlayAndRecord
because I need to use audioRouteOverride:
(I queried this in Feb 2016)
The code below shows how AVAudioSession
was initialised. What puzzles me is that this is the same code that produced audio back then even though player.delegate = self;
was specified two lines above the setDelegate:player
statement (see below).
The latest Apple documentation also says to
Use the notifications described in the Responding to Audio Session Notifications ...
and invites me to download Beta software. But first it would be better to deal with a problem I might have created. My problem is likely to be a result of changes made to the UI (where buttons activate sine tones synthesised from a look up table).
Before I back track through revisions made over the past few weeks I am posting code related to my problem in case it explains why I do not hear audio. I’d be really grateful if anyone can point out something I haven’t noticed. Thanks
float sampleRate = 44100.0f;
// Initialise the audio buffer.
player = [[AudioBufferPlayer alloc] initWithSampleRate:sampleRate channels:1 bitsPerChannel:16 packetsPerBuffer:1024];
player.delegate = self;
player.gain = 0.9f;
[[AVAudioSession sharedInstance] setActive:YES error:nil];
// [[AVAudioSession sharedInstance] setDelegate:player];
[player start];
(A full listing of the initial code is available using links found here).