Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 降低一种声音的音量,而另一种声音在上面播放_Ios_Swift_Swift3 - Fatal编程技术网

Ios 降低一种声音的音量,而另一种声音在上面播放

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

在我的MenuScene.swift中,我在游戏开始时有一系列随机播放的声音:

       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