get current system volume level on iPhone

烂漫一生 提交于 2019-11-27 09:29:01
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;

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

swift 3.0

..

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

Add MediaPlayer Framework into your project

.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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!