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.
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.
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.
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
OSStatus result = AudioSessionSetProperty( kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride );
Assert(result == kAudioSessionNoError);
iOS 6+ version
NSError* error;
AVAudioSession* session = [AVAudioSession sharedInstance];
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With