![](/img/trans.png)
[英]AudioKit - How to use AKAmplitudeTracker threshold callback?
[英]callback for AKButton in Audiokit
我試圖按照Audiokit Docs我的代碼上的說明,了解如何將回調附加到AudioKit上的按鈕:
import UIKit
import AudioKit
import AudioKitUI
class ViewController: UIViewController {
let sounds = AKSampler()
@IBOutlet weak var tam: AKButton!
override func viewDidLoad() {
do {
let hiTomFile = try AKAudioFile(readFileName: "hi_tom_D2.wav")
try sounds.loadAudioFiles([hiTomFile])
AudioKit.output = sounds
} catch {
print ("error reading file")
}
do {
try AudioKit.start()
} catch {
AKLog("AudioKit did not start!")
}
// Bad access here!
tam.callback = { button in self.sounds.play() }
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
但是我訪問不好。 關於我在做什么錯的任何提示嗎?
我能夠使您的按鈕正常工作。 您在情節提要中有一個UIButton,但我創建了一個通用的UIView,將類從“ AudioKitUI”模塊更改為“ AKButton”,然后將其連接到“ tam”聲明,然后單擊它運行回調,沒有錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.