gpt4 book ai didi

ios - 如何限制按钮的音量(Swift)

转载 作者:搜寻专家 更新时间:2023-11-01 07:07:32 26 4
gpt4 key购买 nike

如何限制按钮的音量(Swift)

我有为按钮添加声音的代码。

我怎样才能做到无论设备的声音状态如何,按键的音量始终处于同一水平?

var audioPlayer = AVAudioPlayer()

@IBAction func Sound(_ sender: UIButton) {
guard UserDefaults.standard.bool(forKey: "SwitchState2") else { return }
audioPlayer.play()
}

override func viewDidLoad() {
super.viewDidLoad()
let music = Bundle.main.path(forResource: "PBOING1", ofType: "WAV")
do {
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: music! ))
}
catch{
print(error)
}
}

最佳答案

尝试设置音量:audioplayer.volume = 0.0 到 1.0

您可以在此处阅读有关 AVAudioPlayer 的更多信息:

https://developer.apple.com/documentation/avfoundation/avaudioplayer/1389330-volume

关于ios - 如何限制按钮的音量(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47122519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com