superturboryan/controlkit
**ControlKit** is a minimal Swift Package enabling control of media playback and device volume.
Installation
Add ControlKit as a dependency in your Xcode project:
- Go to File > Add Package Dependenciesβ¦
- Enter the package URL in the search bar:
https://github.com/superturboryan/ControlKit.git- Choose the libraries you want to include:
[Screenshot 2024-10-28 at 17 46 50]
Requirements
SpotifyController requires a Spotify Client ID and Redirect URL to authorize with & control the Spotify app.
Add a URL Type to the target's Info.plist.
- Create an app in the Spotify Developer Dashboard
to get a client ID and register your redirect URL (scheme).
<img width="1007" alt="Screenshot 2024-10-29 at 17 31 24" src="https://github.com/user-attachments/assets/895c8092-4a9d-4526-9f85-5da7b868fbc1">
Warning π
The Spotify access token is not persisted across app launches by default.
You must provide an object conforming to DAO<String> if you want the access token to be persisted.
Usage
Control
import Control
// π Decrement system volume
Control.Volume.decrease()
// π΅οΈββοΈ Check if audio is being played (by another app)
if Control.Playback.isAudioPlaying {
// ππΊ
}
// βοΈ Skip to next track (Apple Music only - use Controllers.SpotifyController for Spotify π)
Control.Playback.AppleMusic.skipToNextTrack()
// 𫨠Vibrate
Control.Haptics.vibrate()Controllers
// App.swift
import Controllers
import SwiftUI
@main struct YourApp: App {
@StateObject var spotify = SpotifyController(
config: .init(
clientID: Secrets.clientID,
redirectURL: "controlkit://spotify"
)
)
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(spotify)
.onOpenURL { spotify.setAccessToken(from: $0) } // Parse access token from URL
}
}
func skipToNextSpotifyTrack() {
spotify.skipToNextTrack()
}
}
// Secrets.swift π
// Don't forget to gitignore this π
enum Secrets {
static let clientID = "<your client id>"
}Dependencies
π AVFAudio π Media Player π¦ SpotifyiOS
Contributing
Contributions and feedback are welcome! π§βπ»π©βπ»
Here are a few guidelines:
- You can open an Issue or raise a PR π€
- Commit messages should contain emojis β€οΈ and be signed π
- Workflows should be green π’
mainshould be linear π
Package Metadata
Repository: superturboryan/controlkit
Default branch: main
README: README.md