Skip to content

Commit 55878ee

Browse files
Merge pull request #639 from Alexander5015/spotify-controller-fixes
Fix Spotify Playback State Synchronization
2 parents 24ca99c + 7271faf commit 55878ee

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

boringNotch/MediaControllers/SpotifyController.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class SpotifyController: MediaControllerProtocol {
1717

1818
var playbackStatePublisher: Published<PlaybackState>.Publisher { $playbackState }
1919

20+
//Constant for time between command and update
21+
let commandUpdateDelay: Duration = .milliseconds(25)
22+
2023
init() {
2124
setupPlaybackStateChangeObserver()
2225
DispatchQueue.main.async { [weak self] in
@@ -67,17 +70,26 @@ class SpotifyController: MediaControllerProtocol {
6770

6871
func seek(to time: Double) {
6972
executeCommand("set player position to \(time)")
70-
updatePlaybackInfo()
73+
Task {
74+
try? await Task.sleep(for: commandUpdateDelay)
75+
updatePlaybackInfo()
76+
}
7177
}
7278

7379
func toggleShuffle() {
7480
executeCommand("set shuffling to not shuffling")
75-
updatePlaybackInfo()
81+
Task {
82+
try? await Task.sleep(for: commandUpdateDelay)
83+
updatePlaybackInfo()
84+
}
7685
}
7786

7887
func toggleRepeat() {
7988
executeCommand("set repeating to not repeating")
80-
updatePlaybackInfo()
89+
Task {
90+
try? await Task.sleep(for: commandUpdateDelay)
91+
updatePlaybackInfo()
92+
}
8193
}
8294

8395
func isActive() -> Bool {

0 commit comments

Comments
 (0)