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];