Reputation: 574
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.
Upvotes: 5
Views: 2658
Reputation: 14580
iOS 6+ version
NSError* error;
AVAudioSession* session = [AVAudioSession sharedInstance];
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
Upvotes: 2
Reputation: 447
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.
Upvotes: 1
Reputation: 13549
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
OSStatus result = AudioSessionSetProperty( kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride );
Assert(result == kAudioSessionNoError);
Upvotes: 6