0
我的應用程序中有一個AVAudioPlayer,我添加了一個功能,用戶可以按遙控器上的播放/暫停按鈕來播放/暫停AVAudioPlayer。我在我的App Delegate中有這樣的代碼:將操作添加到Apple TV遙控器播放/暫停按鈕
func initializePlayButtonRecognition() {
addPlayButtonRecognizer(#selector(AppDelegate.handlePlayButton(_:)))
}
func addPlayButtonRecognizer(_ selector: Selector) {
let playButtonRecognizer = UITapGestureRecognizer(target: self, action:selector)
playButtonRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue as Int)]
self.window?.addGestureRecognizer(playButtonRecognizer)
}
func handlePlayButton(_ sender: AnyObject) {
if audioPlayer.isPlaying {
audioPlayer.pause() {
} else {
audioPlayer.play()
}
}
}
AVAudioPlayer的名稱是audioPlayer。我在代碼中說過,但App Delegate沒有從PlayerViewController引用AVAudioPlayer。我該怎麼做呢?
謝謝,但我已經補充說。問題是,應用程序委託不知道什麼audioPlayer是「使用未解析的標識符'audioPlayer' – iFunnyVlogger