Listen for AirPods connection changes (#1186)

* Toggle the video player's pause or play state when airpods are connected or disconnected.

* Remove AVAudioSession route change listener in favor of the remote command center callbacks.
This commit is contained in:
Daniel Chick 2024-08-19 15:46:12 -05:00 committed by GitHub
parent c0ca96c1ca
commit e5f408a867
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 0 deletions

View File

@ -6,10 +6,12 @@
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//
import AVFoundation
import Combine
import Defaults
import Foundation
import JellyfinAPI
import MediaPlayer
import UIKit
import VLCUI
@ -66,6 +68,14 @@ class VideoPlayerManager: ViewModel {
private var currentProgressWorkItem: DispatchWorkItem?
private var hasSentStart = false
private let commandCenter = MPRemoteCommandCenter.shared()
override init() {
super.init()
setupControlListeners()
}
func selectNextViewModel() {
guard let nextViewModel else { return }
currentViewModel = nextViewModel
@ -285,4 +295,18 @@ class VideoPlayerManager: ViewModel {
logger.debug("sent progress task")
}
}
func setupControlListeners() {
commandCenter.pauseCommand.addTarget { [weak self] _ in
self?.proxy.pause()
return .success
}
commandCenter.playCommand.addTarget { [weak self] _ in
self?.proxy.play()
return .success
}
}
}