我有没有办法在iPhone上获得当前的系统音量?
我想也许有办法制作MPVolumeView
并从中获取价值。
答案 0 :(得分:25)
musicPlayer = [[MPMusicPlayerController iPodMusicPlayer];
currentVolume = musicPlayer.volume;
现在从iOS8.0开始不推荐使用,请尝试以下
#import <AVFoundation/AVAudioSession.h>
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
CGFloat volume = audioSession.outputVolume;
答案 1 :(得分:2)
Celestial.framework有一个AVSystemController
类,可让您获取和设置当前音量。不幸的是,这是私人课程,所以Apple不会在App Store提交的内容中接受它
如果有帮助,您可以稍微滥用公开MPVolumeView
课程:http://www.stormyprods.com/blogger/2008/09/proper-usage-of-mpvolumeview-class.html
答案 2 :(得分:0)
将MediaPlayer Framework添加到您的项目中
.h(头文件)
{
MPMusicPlayerController *musicPlayer;
}
.m(实施文件)
- (void)viewDidLoad
{
//get device volume level
musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
float deviceVolumeLevel = musicPlayer.volume;
NSLog(@"Current device volume level : %f",deviceVolumeLevel);
}
答案 3 :(得分:0)
swift 3.0
...
import AVKit
..
// get current level:
let audioSession = AVAudioSession.sharedInstance()
let volume : Float = audioSession.outputVolume