Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the volume without a volume slider on an iphone

I need your help. How should I proceed to change the sound volume in my app. I don't want to use a volume slider. Instead I have an UIImageView which is a volume knob, in which I rotate clockwise to increase, and anti clockwise to decrease the sound volume. The rotation is just an animation and I've already done that part.

I need your help and advice on how to increase/decrease the volume. Thanks

like image 274
awlcs Avatar asked Aug 11 '10 13:08

awlcs


People also ask

How do you manually adjust volume on iPhone?

When you're on the phone or listening to songs, movies, or other media on iPhone, you can use the buttons on the side of your device to adjust the audio volume. Otherwise, the buttons control the volume for the ringer, alerts, and other sound effects. You can also use Siri to turn the volume up or down.

Can I set the volume on my iPhone lower than the slider goes?

In any event, using the touch screen you can finely adjust the volume on the big slider all the way down to barely audible.

Does iPhone have separate volume controls?

Here's why: iOS has two different volume controls - ringer volume, which controls the volume for the ringer, notifications and system alerts, and alarms; and media volume, which controls the in-app volume for games, music, and videos in addition to calls.


1 Answers

I view this as a bug in Apple's code and have reported it to them both with Bug Reports and in person, but since they insist its a feature, you might as well benefit from it.

Use the following code to change your application's volume:

[[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolume];

This will only work after you have established your audio session, either by playing a sound or by setting it active as such:

[[AVAudioSession sharedInstance] setActive:YES error:NULL];

Note as that you'll need MediaPlayer.framework and AVFoundation.framework and that the volume is between 0.0 and 1.0.

like image 161
Eddie Marks Avatar answered Oct 01 '22 01:10

Eddie Marks