Sophie Alpert
Sophie Alpert

Reputation: 143194

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.

Upvotes: 9

Views: 15052

Answers (4)

bpolat
bpolat

Reputation: 3908

Add MediaPlayer Framework into your project

enter image description here

.h (Header file)

{

  MPMusicPlayerController *musicPlayer; 

}

.m (implementation file)

- (void)viewDidLoad

{

//get device volume level

   musicPlayer = [MPMusicPlayerController iPodMusicPlayer];

   float deviceVolumeLevel = musicPlayer.volume;

   NSLog(@"Current device volume level : %f",deviceVolumeLevel);
}

Upvotes: 0

ingconti
ingconti

Reputation: 11666

swift 3.0

..

import AVKit
..
    // get current level:
    let  audioSession = AVAudioSession.sharedInstance()
    let volume : Float = audioSession.outputVolume

Upvotes: 0

amergin
amergin

Reputation: 3176

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;

Upvotes: 26

rpetrich
rpetrich

Reputation: 32336

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

Upvotes: 2

Related Questions