-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add player, playbackstate primitives, reorg files, continue apple mus…
…ic progress
- Loading branch information
1 parent
c2fa6d4
commit 12a312f
Showing
5 changed files
with
115 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
|
||
struct PlayerStateNotification { | ||
let player: Player | ||
let playbackState: PlaybackState | ||
let songName: String? | ||
let artistName: String? | ||
let albumName: String? | ||
|
||
init?(_ player: Player, _ notification: Notification) { | ||
guard let playbackStateString = notification.userInfo?["Player State"] as? String else { | ||
return nil | ||
} | ||
|
||
self.player = player | ||
self.playbackState = PlaybackState(state: playbackStateString) | ||
self.songName = notification.userInfo?["Name"] as? String | ||
self.artistName = notification.userInfo?["Artist"] as? String | ||
self.albumName = notification.userInfo?["Album"] as? String | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
enum PlaybackState { | ||
case paused | ||
case playing | ||
case stopped | ||
|
||
init<T: RawRepresentable>(_ descriptor: T?) where T.RawValue == UInt32 { | ||
switch descriptor?.rawValue { | ||
case 0x6b505370: | ||
self = .paused | ||
case 0x6b505350, 0x6b505352, 0x6b505346: // playing, rewinding, fast-forwarding | ||
self = .playing | ||
default: | ||
self = .stopped | ||
} | ||
} | ||
|
||
init(state: String) { | ||
switch state { | ||
case "Paused": | ||
self = .paused | ||
case "Playing": | ||
self = .playing | ||
default: | ||
self = .stopped | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
enum Player: String { | ||
case music = "com.apple.music" | ||
case spotify = "com.spotify.client" | ||
|
||
var bundleID: String { | ||
return self.rawValue | ||
} | ||
} |