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:
parent
c0ca96c1ca
commit
e5f408a867
|
@ -6,10 +6,12 @@
|
||||||
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
|
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import AVFoundation
|
||||||
import Combine
|
import Combine
|
||||||
import Defaults
|
import Defaults
|
||||||
import Foundation
|
import Foundation
|
||||||
import JellyfinAPI
|
import JellyfinAPI
|
||||||
|
import MediaPlayer
|
||||||
import UIKit
|
import UIKit
|
||||||
import VLCUI
|
import VLCUI
|
||||||
|
|
||||||
|
@ -66,6 +68,14 @@ class VideoPlayerManager: ViewModel {
|
||||||
private var currentProgressWorkItem: DispatchWorkItem?
|
private var currentProgressWorkItem: DispatchWorkItem?
|
||||||
private var hasSentStart = false
|
private var hasSentStart = false
|
||||||
|
|
||||||
|
private let commandCenter = MPRemoteCommandCenter.shared()
|
||||||
|
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
setupControlListeners()
|
||||||
|
}
|
||||||
|
|
||||||
func selectNextViewModel() {
|
func selectNextViewModel() {
|
||||||
guard let nextViewModel else { return }
|
guard let nextViewModel else { return }
|
||||||
currentViewModel = nextViewModel
|
currentViewModel = nextViewModel
|
||||||
|
@ -285,4 +295,18 @@ class VideoPlayerManager: ViewModel {
|
||||||
logger.debug("sent progress task")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue