有没有办法设置 AVAudioSession 输出音量?
self.audioSession = AVAudioSession.sharedInstance()
self.audioSession.setActive(true, error: nil)
self.audioSession.addObserver(self, forKeyPath: "outputVolume", options: NSKeyValueObservingOptions.New, context: nil)
self.audioSession.outputVolume
目前我可以访问 outputVolume,但我很难找到设置它的方法。
谢谢!
最佳答案
outputVolume
属性是只读的。这是因为 Apple 坚信,如果应用意外地修改超出用户控制的音量,良好的用户体验将会被破坏。
来自 AVAudioSession 文档:
The system wide output volume can be set directly only by the user; to provide volume control in your app, use the MPVolumeView class
所以这是您唯一(简单)的选择...
MPVolumeView *myVolumeView =
[[MPVolumeView alloc] initWithFrame:frame];
[self.view addSubview: myVolumeView];
关于ios - Swift:设置 AVAudioSession 输出音量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28617635/