Ios 降低一种声音的音量,而另一种声音在上面播放
在我的MenuScene.swift中,我在游戏开始时有一系列随机播放的声音:Ios 降低一种声音的音量,而另一种声音在上面播放,ios,swift,swift3,Ios,Swift,Swift3,在我的MenuScene.swift中,我在游戏开始时有一系列随机播放的声音: let soundNames = [ "Sound/01.mp3", "Sound/02.mp3", "Sound/03.mp3" ] let randomSoundName = soundNames[Int(arc4random_uniform(UInt32(soundNames.count)))] _ = self.run(SK
let soundNames = [
"Sound/01.mp3",
"Sound/02.mp3",
"Sound/03.mp3"
]
let randomSoundName = soundNames[Int(arc4random_uniform(UInt32(soundNames.count)))]
_ = self.run(SKAction.playSoundFileNamed(randomSoundName, waitForCompletion: false))
…在我的GameViewController.swift中,我有一个在游戏开始时播放的背景曲目:
// Start the background music:
if let musicPath = Bundle.main.path(forResource:
"Sound/BackgroundMusic.wav", ofType: nil) {
let url = URL(fileURLWithPath: musicPath)
do {
musicPlayer = try AVAudioPlayer(contentsOf: url)
musicPlayer.numberOfLoops = -1
musicPlayer.prepareToPlay()
musicPlayer.play()
}
catch { /* Couldn't load music file */ }
}
当随机声音在背景音轨顶部播放时,我如何降低背景音轨的音量?您可以尝试
audioPlayer?.volume=0.7
自定义音量。我将如何/在何处实现这一点?musicPlayer?.volume=0.7
您必须将其放在需要的地方,您可以通过编程方式将音量从0.0更改为1.0