1
votes

My app is currently playing sounds based on ringer volume. It is annoying to many users seeing its a soundboard app. I've noticed that when an ad pops up featuring a video, the volume control then changes to system volume after closing the ad and resuming use of the app. With this in mind I was hoping to use a dummy(silent) sound played via AVAudioPlayer upon launch of the app, somewhat tricking it into using the system sound controller rather than ringer. Here is my current code im using to play sounds:

    func playSound(fNameOnly : String, sFileExt : String = "mp3"){

    let soundUrl = NSBundle.mainBundle().URLForResource(fNameOnly, withExtension: sFileExt)
    var SSID : SystemSoundID = 0
    if gSoundsOn && soundUrl != nil {

        AudioServicesCreateSystemSoundID(soundUrl!, &SSID)

        AudioServicesPlaySystemSoundWithCompletion(SSID){
            AudioServicesDisposeSystemSoundID(SSID)
            self.soundComplete(SSID)
        }

        self.soundArray.append(SSID)
    }
}

I was hoping someone could help me with creating a func/method to play the dummy sound clip via AVAudioPlayer upon launch/opening of the app.

1

1 Answers

0
votes

I also have this problem.

The issue is that AudioServicesPlaySystemSound always uses the ringer volume, while AVAudioPlayer uses the volume setting. Playing an AVAudio sound before the SystemSound will not change that behavior. It may appear that way, because now when you hit the volume buttons, the 'volume' control pops up.. but you will notice that it has no effect on the system sounds being played. It is a real pain.

Currently I let the users know that they need to have the ringer sound setting on their device set to 'Change with buttons'. This allows them to change the volume of the ringer while in the game. Still not a great solution in my opinion. I'm afraid that the only solution is to use AVAudioPlayer for all sounds.. which may have some undesirable delays when you need a quick sound (like on a button click).