mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Atoll: pause Spotify Canvas in dynamic island when audio pauses
Subscribe DynamicIslandArtworkLoopController to MusicManager.isPlaying so the looping AVQueuePlayer pauses and resumes with playback state. Signed-off-by: Jis G Jacob <jackeagle102@gmail.com>
This commit is contained in:
parent
be09d93d2d
commit
3117bdb919
1 changed files with 18 additions and 1 deletions
|
|
@ -29,6 +29,7 @@ import AVFoundation
|
|||
private final class DynamicIslandArtworkLoopController {
|
||||
let player: AVQueuePlayer
|
||||
private var looper: AVPlayerLooper?
|
||||
private var playbackStateCancellable: AnyCancellable?
|
||||
|
||||
init(url: URL) {
|
||||
let item = AVPlayerItem(url: url)
|
||||
|
|
@ -36,12 +37,28 @@ private final class DynamicIslandArtworkLoopController {
|
|||
player.isMuted = true
|
||||
player.actionAtItemEnd = .none
|
||||
looper = AVPlayerLooper(player: player, templateItem: item)
|
||||
player.play()
|
||||
|
||||
if MusicManager.shared.isPlaying {
|
||||
player.play()
|
||||
}
|
||||
|
||||
playbackStateCancellable = MusicManager.shared.$isPlaying
|
||||
.removeDuplicates()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] isPlaying in
|
||||
guard let self else { return }
|
||||
if isPlaying {
|
||||
self.player.play()
|
||||
} else {
|
||||
self.player.pause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
player.pause()
|
||||
looper = nil
|
||||
playbackStateCancellable = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue