Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change audio route when the audio is playing

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.

like image 279
FatalError Avatar asked Sep 11 '12 23:09

FatalError


People also ask

How do I change audio output calls?

Tap the small button at the top right of the player notification tile. In the media player pop-up, you'll see a list of connected audio devices. Tap the one you want to switch to.

What is call audio routing on iPhone?

You can automatically direct the audio of phone or FaceTime calls to the iPhone speaker, a Bluetooth headset, or your hearing devices. iPhone can also automatically answer calls after a specific duration. Go to Settings > Accessibility > Touch > Call Audio Routing, then choose an audio destination.


3 Answers

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
OSStatus result = AudioSessionSetProperty( kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride );
Assert(result == kAudioSessionNoError);
like image 131
Tommy Devoy Avatar answered Sep 28 '22 16:09

Tommy Devoy


iOS 6+ version

NSError* error;

AVAudioSession* session = [AVAudioSession sharedInstance];

[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
like image 41
CupawnTae Avatar answered Sep 28 '22 16:09

CupawnTae


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.

like image 33
Topsakal Avatar answered Sep 28 '22 15:09

Topsakal