SoundPlayer

class SoundPlayer

Creates a strong reference to AVAudioPlayer and plays a sound file. Convenience class to declutter controller classes.

Example Use

let soundPlayer : SoundPlayer? = SoundPlayer()
guard let player = self.soundPlayer else {return}
// player.playSound(fileName: String, volume: Float)
player.playSound("sound.mp3", 0.5)

Author

Cadence Holmes 2018
  • Undocumented

    Declaration

    Swift

    var player: AVAudioPlayer?
  • Undocumented

    Declaration

    Swift

    var numberOfLoops: Int
  • Undocumented

    Declaration

    Swift

    init()
  • Handles checking for AVAudioPlayer and playing a sound.

    Throws

    print(error.localizedDescription)

    Declaration

    Swift

    func playSound(_ fileName: String, _ volume: Float)

    Parameters

    fileName

    String - file name as it appears in Sounds.xcassets

    volume

    Float - volume scaled 0.0 - 1.0