Change iPhone sound through speaker, headphone or Bluetooth

I would like to create an application that allows the user to choose an audio route. those. the user can choose whether to play sound through headphones, speaker or Bluetooth. My application does not play sound, but I want if the song is playing on the iPhone using the built-in music application or any other media player, when I select the speaker from my application, the song should play through the speaker even if the headset is connected. Is it possible to control sound routing at the system level from another application.

+3
source share
4 answers

I wanted to do something like this at some point. If I remember correctly ... there is a physical switch in the device that closes when the headphones are inserted. Effectively makes sound routing impossible, as there are no longer any connections between the speakers and the rest of the device.

+1
source

I have not found a better way than using part of the volume representation of the media player.

The following code snippet:

// Display the audio route button (Bluetooth / Speaker / iPhone)
UIView *mpVolumeViewParentView = [[UIView alloc] initWithFrame:CGRectMake(5, 50, 50, 40)];
mpVolumeViewParentView.backgroundColor = [UIColor clearColor];
mpVolumeViewParentView.clipsToBounds = YES;

MPVolumeView *systemVolumeSlider = [[MPVolumeView alloc] initWithFrame:CGRectMake(-290, 0, 320, 40)];
[mpVolumeViewParentView addSubview:systemVolumeSlider];
[systemVolumeSlider release];

[self.view addSubview:mpVolumeViewParentView];
[mpVolumeViewParentView release];

This is not an ideal solution, but it does the job.

+1
source
0
source

Starting with iOS 4.2, MPVolumeView has two properties for disabling unwanted elements:

showsVolumeSlider
showsRouteButton
0
source

Source: https://habr.com/ru/post/1774011/


All Articles