https://github.com/superturboryan/controlkit
π¦ Swift Package providing simplified APIs for controlling device features
https://github.com/superturboryan/controlkit
avfoundation control ios iphone playback-controls swift swift-package volume-control
Last synced: about 1 year ago
JSON representation
π¦ Swift Package providing simplified APIs for controlling device features
- Host: GitHub
- URL: https://github.com/superturboryan/controlkit
- Owner: superturboryan
- License: mit
- Created: 2024-10-28T17:04:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-05T21:25:32.000Z (about 1 year ago)
- Last Synced: 2025-06-05T21:29:48.671Z (about 1 year ago)
- Topics: avfoundation, control, ios, iphone, playback-controls, swift, swift-package, volume-control
- Language: Swift
- Homepage:
- Size: 24.4 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


# ControlKit
**ControlKit** is a minimal Swift Package enabling control of media playback and device volume.
[](https://swiftpackageindex.com/superturboryan/ControlKit) [](https://swiftpackageindex.com/superturboryan/ControlKit)   
### TLDR
Control the device's volume with one line:
```swift
Control.Volume.increase() // π π
```
## Installation
Add ControlKit as a dependency in your Xcode project:
1. Go to **File > Add Package Dependenciesβ¦**
2. Enter the package URL in the search bar:
```
https://github.com/superturboryan/ControlKit.git
```
3. Choose the libraries you want to include:

## Requirements
[`SpotifyController`](Sources/Controllers/SpotifyController.swift) requires a Spotify _Client ID_
and _Redirect URL_ to authorize with & control the Spotify app.
1. [Define a custom URL scheme for your app](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app).
Add a `URL Type` to the target's `Info.plist`.
2. Create an app in the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard)
to get a _client ID_ and register your _redirect URL_ (scheme).

### Warning π
The Spotify access token is **not persisted across app launches** by default.
You must provide an object conforming to **`DAO`** if you want the access token to be persisted.
## Usage
### Control
```swift
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
```swift
// 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 = ""
}
```
## Dependencies
π [AVFAudio](https://developer.apple.com/documentation/avfaudio)
π [Media Player](https://developer.apple.com/documentation/mediaplayer/)
π¦ [SpotifyiOS](https://github.com/spotify/ios-sdk)
## Contributing
Contributions and feedback are welcome! π§βπ»π©βπ»
Here are a few guidelines:
- You can [open an Issue](https://github.com/superturboryan/ControlKit/issues/new) or raise a PR π€
- Commit messages should contain emojis β€οΈ and be [signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) π
- [Workflows](https://github.com/superturboryan/ControlKit/actions) should be green π’
- `main` should be [linear](https://stackoverflow.com/questions/20348629/what-are-the-advantages-of-keeping-linear-history-in-git) π