A swift package to make it a lot easier to play audio in your app.
In Xcode go to File -> Add Packages... -> Search or Enter Package URL
and paste in the repo's url: https://github.com/pedroesli/KeyAudioManager
To be able to play an audio using the KeyAudioManager, you must first provide the audios file name and file extension using the add
method
let audioManager = KeyAudioManager()
// Add the audios
do {
try audioManager.addAudio(key: "buttonSound", audioFileName: "Button Sound", fileExtension: "mp3")
try audioManager.addAudio(key: "song", audioFileName: "Main Menu Song", fileExtension: "mp3")
}
catch{
print("Error adding audio file: \(error)")
}
// Play an audio using its key
audioManager.play(key: "song")
audioManager.play(key: "song")
// Or to play an audio after the first one is done playing
audioManager.play(key: "buttonSound"){
audioManager.play(key: "song")
}
audioManager.removeAudio(key: "buttonSound")
audioManager.pause(key: "song")
audioManager.stop(key: "song")
// Values ranging from 0.0 for silence to 1.0 for full volume.
audioManager.volume(key: "song", 0.5)
// repeats and audio indefinitely with a time interval in between the audios
audioManager.playLoop(key: "song", 2.0)
// To stop repeating audio
audioManager.stopLoop()
// play a series of audio in a sequence with a time interval (seconds) in between the audios
audioManage.playInSequence("song", "buttonSound", "sound1", "song", timeInterval: 2)