Question

So far, my app plays audio through the iphone receiver (phone-call speaker) by using

AVAudioSession *ss = [AVAudioSession sharedInstance];
[ss overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];

I give the user an opportunity to set the volume using an MPVolumeView

MPVolumeView *volumeView1 = [[MPVolumeView alloc] initWithFrame:CGRectMake(4, 316, 300, 50)];
[volumeView1 sizeToFit];
[self.view addSubview:volumeView1];

However, adjusting the MPVolumeView is only affecting the volume of the phone's big speaker, not the receiver.

How can I present the user the opportunity to adjust the receiver volume when there is not a phone call in session?

Was it helpful?

Solution 2

I got it to work, the following code allows the user to set the receiver's volume, although an audio file must be playing in the background. Also, the AVAudioPlayer must be a @property.

AVAudioSession *sharedSession = [AVAudioSession sharedInstance];
[sharedSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[sharedSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];

MPVolumeView *volumeView1 = [[MPVolumeView alloc] initWithFrame:CGRectMake(4, 316, 300, 50)];
[volumeView1 sizeToFit];
[self.view addSubview:volumeView1];

NSURL *soundFileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"silence" ofType:@"m4a"]];
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
[self.audioPlayer play];

OTHER TIPS

This is simply not allowed by the API, through public methods anyway. See apple's documentation on setting volume: https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top