3 // Protocol to obtain the track from Spotify
4 @objc protocol SpotifyTrack {
5 @objc optional var name: String {get}
6 @objc optional var artist: String {get}
9 // Protocol to interact with Spotify
10 @objc protocol SpotifyApplication {
11 @objc optional var currentTrack: SpotifyTrack? {get}
14 extension SBApplication: SpotifyApplication {}
16 // Source that reads track artist and name from current Spotify track
17 class SpotifySource: Source {
19 // Calls the spotify API and returns the current track
20 var currentTrack: Track? {
22 if let spotify: SpotifyApplication = SBApplication(bundleIdentifier: "com.spotify.client") {
23 if let application = spotify as? SBApplication {
24 if !application.isRunning {
29 // Attempt to fetch the title from a song
31 if let currentTrack = spotify.currentTrack {
32 if let track = currentTrack {
33 if let name = track.name {
34 if let artist = track.artist {
36 return Track(withName: name, andArtist: artist)
46 func enable() -> Bool { return true }
47 func disable() -> Bool { return true }
48 func reset() -> Bool { return true }