5
votes

I have an audio file that plays using avaudioplayer, I want to able to play the sound on the device receiver or speaker when the audio is playing when the user presses a button. How can I do that ? Currently it just plays on whatever was selected before the audio started playing.

3

3 Answers

6
votes
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
OSStatus result = AudioSessionSetProperty( kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride );
Assert(result == kAudioSessionNoError);
2
votes

iOS 6+ version

NSError* error;

AVAudioSession* session = [AVAudioSession sharedInstance];

[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
1
votes

You can add MPVolume control (link to documentation) to your user interface and set showsVolumeSlider = NO and showsRouteButton = YES.

User will have a route button to route the audio to a device of their choice.