Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lower the volume of music in swift?

I am creating a SpriteKit Game with background music looping. The problem is that the music is too loud. How do I lower the volume?

Here is the code I used to set up the music

    var backGroundMusic = AVAudioPlayer()
    var bgMusicUrl:NSURL = NSBundle.mainBundle().URLForResource("BackGround", withExtension: "wav")
    backGroundMusic = AVAudioPlayer(contentsOfURL:bgMusicUrl, error: nil)
    backGroundMusic.numberOfLoops = (-1)
    backGroundMusic.prepareToPlay()
    backGroundMusic.play()
like image 684
Oliver Shi Avatar asked Aug 19 '14 23:08

Oliver Shi


1 Answers

Have you tried this?

backGroundMusic.volume = 0.5

Volume goes from 0.0 to 1.0 (full volume). https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/index.html

like image 157
Mariano Ruggiero Avatar answered Nov 16 '22 12:11

Mariano Ruggiero