Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get current system volume level on iPhone

Is there a way I can get the current system volume level on the iPhone?

I'm thinking maybe there's a way to make an MPVolumeView and get the value from that.

like image 397
Sophie Alpert Avatar asked Feb 21 '09 07:02

Sophie Alpert


People also ask

Is there an internal 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.


2 Answers

musicPlayer = [[MPMusicPlayerController iPodMusicPlayer];

currentVolume = musicPlayer.volume;

This is now deprecated as of iOS8.0 so try the following

#import <AVFoundation/AVAudioSession.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
CGFloat volume = audioSession.outputVolume;
like image 60
amergin Avatar answered Oct 17 '22 09:10

amergin


Celestial.framework has an AVSystemController class that lets you get and set the current volume. Unfortunately it is a private class so Apple won't accept it in App Store submissions

If it helps, you can abuse the public MPVolumeView class a bit: http://www.stormyprods.com/blogger/2008/09/proper-usage-of-mpvolumeview-class.html

like image 25
rpetrich Avatar answered Oct 17 '22 09:10

rpetrich