歡迎加入QQ討論群258996829

Swift app聲音管理庫 Chirp

發(fā)布時(shí)間:2017-03-17 20:32  回復(fù):0  查看:4620  感興趣:17  贊:0   最后回復(fù):2017-03-17 20:32  

Swift app聲音管理庫 Chirp,可以通過簡便的方式加載、播放、移除聲音。

示例代碼

prepareSound用于將聲音預(yù)加載到內(nèi)存中。 這會(huì)將聲音的擁有數(shù)量增加1。在調(diào)用playSound之前必須調(diào)用此方法。

/* MyViewController.swift */

override func viewDidLoad() {
    super.viewDidLoad()

    // Load sounds into memory
    Chirp.sharedManager.prepareSound("boop") // default extension is .wav
    Chirp.sharedManager.prepareSound("ding.mp3") // so other extensions you must name explicitly
}

通過playSound 播放預(yù)加載的聲音。

func submitButtonTouched(button: UIButton) {
    // Since the sound is already loaded into memory, this will play immediately
    Chirp.sharedManager.playSound("boop") 

    // example function that might get called when you touch a button
    submitForm() 
}

通過removeSound從內(nèi)存中移除聲音。

deinit {
    // Cleanup is really simple!
    Chirp.sharedManager.removeSound("boop")
    Chirp.sharedManager.removeSound("ding.mp3")
    Chirp.sharedManager.removeSound("oops.mp3")

    // If you never loaded the sounds, e.g. viewDidLoad wasn't called, or submission never failed or succeeded,
    // that's ok, because these will function as no-ops
}

相關(guān)開源代碼

您還未登錄,請先登錄

熱門帖子

最新帖子

?