2017-04-15 1 views
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への参照を持っていない。これはどうすればいいですか?

答えて

0

コードが正しいように見えます。 ... tvOSで、離れてallowedPressTypesを設定するから、またのような間接的allowedTouchTypesを定義するために必要とされる期待どおりに動作しない理由を説明できるだけで不足している詳細:

playButtonRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)] 
+0

おかげで、私はすでにそれを追加しました。問題は、App Delegateが、どのaudioPlayerが「未解決の識別情報を使用しているのかわからない」ということです。 'audioPlayer' – iFunnyVlogger

関連する問題