Git Hub
коротко

Swift: Audio

18 января 2017, 23:19

проигрывать кастомный звук

import AVFoundation

/// example:
/// player = AudioHelper()
/// player.prepare("r2d2")
/// player.playSound()
class AudioHelper {
    private var player =  AVAudioPlayer()
    
    func prepare(name:String){
        
        
        let path = Bundle.main.path(forResource: name, ofType: "mp3")
        let url = URL(fileURLWithPath: path!)
        
        do {
            self.player =  try AVAudioPlayer(contentsOf: url)
            self.player.prepareToPlay()
            
        }
        catch{
            print("error plaing sound")
        }
    }
    
    func playSound() {
        player.play()
    }
}
let player = AudioHelper()
 player.prepare("r2d2")
player.playSound()
Поделиться
#iOS   iOS   Swift
Популярное