[tvos] 入力切り替え・テレビ電源切断時の挙動メモ


入力切り替え・テレビ電源切断時に AppDelegate Notification AVPlayer の挙動についてメモ

端末

AppleTV tvOS11.4

AppDelegateについて

UIApplicationDelegate UIApplicationState
入力切り替え(別へ) func applicationWillResignActive(_ application: UIApplication) active
入力切り替え(AppleTVへ) func applicationDidBecomeActive(_ application: UIApplication) active
AppleTVからHDMI抜く func applicationWillResignActive(_ application: UIApplication) active
AppleTVにHDMI差す func applicationDidBecomeActive(_ application: UIApplication) active
TVの電源OFF 反応なし
TVの電源ON 反応なし

AVPlayer、Notificationについて

AVPlayer.rate Notification
入力切り替え(別へ) 0 UIApplicationWillResignActiveNotification
入力切り替え(AppleTVへ) 1 AVAudioSessionRouteChangeNotification
UIApplicationDidBecomeActiveNotification
AppleTVからHDMI抜く 0 UIApplicationWillResignActiveNotification
AppleTVにHDMI差す 1 AVAudioSessionRouteChangeNotification
UIApplicationDidBecomeActiveNotification
TVの電源OFF 反応なし
TVの電源ON 反応なし

ログサンプル

入力切り替え(別へ)

AVPlayer.rate: 0.0
applicationWillResignActive applicationState=>active
Notification.Name(_rawValue: UIApplicationWillResignActiveNotification)
AVPlayer.rate: 0.0

入力切り替え(AppleTVへ)

Notification.Name(_rawValue: AVAudioSessionRouteChangeNotification)
applicationDidBecomeActive applicationState=>active
Notification.Name(_rawValue: UIApplicationDidBecomeActiveNotification)
AVPlayer.rate: 1.0

AppleTVからHDMI抜く

AVPlayer.rate: 0.0
applicationWillResignActive applicationState=>active
Notification.Name(_rawValue: UIApplicationWillResignActiveNotification)
AVPlayer.rate: 0.0

AppleTVにHDMI差す

Notification.Name(_rawValue: AVAudioSessionRouteChangeNotification)
applicationDidBecomeActive applicationState=>active
Notification.Name(_rawValue: UIApplicationDidBecomeActiveNotification)
AVPlayer.rate: 1.0

TVの電源OFF

TV電源ON

スクリーンセーバー

applicationWillResignActive applicationState=>active
Notification.Name(_rawValue: UIApplicationWillResignActiveNotification)
AVPlayer.rate: 0.0

スリープ

applicationDidEnterBackground applicationState=>background
Notification.Name(_rawValue: UIApplicationDidEnterBackgroundNotification)
application(_:shouldSaveApplicationState:) applicationState=>background
application(_:willEncodeRestorableStateWith:) applicationState=>background
Notification.Name(_rawValue: AVAudioSessionInterruptionNotification)