mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Merge pull request #455 from StudioKeys/pr-440
Atoll: pause Spotify Canvas in dynamic island when audio pauses
This commit is contained in:
commit
81ed7c1ec2
1 changed files with 18 additions and 1 deletions
|
|
@ -29,6 +29,7 @@ import AVFoundation
|
||||||
private final class DynamicIslandArtworkLoopController {
|
private final class DynamicIslandArtworkLoopController {
|
||||||
let player: AVQueuePlayer
|
let player: AVQueuePlayer
|
||||||
private var looper: AVPlayerLooper?
|
private var looper: AVPlayerLooper?
|
||||||
|
private var playbackStateCancellable: AnyCancellable?
|
||||||
|
|
||||||
init(url: URL) {
|
init(url: URL) {
|
||||||
let item = AVPlayerItem(url: url)
|
let item = AVPlayerItem(url: url)
|
||||||
|
|
@ -36,12 +37,28 @@ private final class DynamicIslandArtworkLoopController {
|
||||||
player.isMuted = true
|
player.isMuted = true
|
||||||
player.actionAtItemEnd = .none
|
player.actionAtItemEnd = .none
|
||||||
looper = AVPlayerLooper(player: player, templateItem: item)
|
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 {
|
deinit {
|
||||||
player.pause()
|
player.pause()
|
||||||
looper = nil
|
looper = nil
|
||||||
|
playbackStateCancellable = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue