本文介绍了Swift:设置AVAudioSession输出音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以设置AVAudioSession outputVolume?
Is there a way to set the AVAudioSession outputVolume?
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,但是我在寻找一种设置方式上遇到了麻烦.
Currently I am able to access the outputVolume, but I am having troubles of finding a way to set it.
谢谢!
推荐答案
outputVolume
属性是只读的.这是由于Apple坚信,如果应用程序意外地将音量更改超出用户控制,则良好的用户体验将被破坏.
The outputVolume
property is read-only. This is due to Apple's conviction that a good user experience will be broken if apps unexpectedly modify sound volume beyond user control.
来自AVAudioSession文档:
From the AVAudioSession docs:
这是您唯一的(简单)选项...
So this is your only (easy) option...
MPVolumeView *myVolumeView =
[[MPVolumeView alloc] initWithFrame:frame];
[self.view addSubview: myVolumeView];
这篇关于Swift:设置AVAudioSession输出音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!