Skip to content

Latest commit

 

History

History
127 lines (85 loc) · 4.34 KB

README.md

File metadata and controls

127 lines (85 loc) · 4.34 KB

ControlKit Light ControlKit Dark

ControlKit

ControlKit is a minimal Swift Package enabling control of media playback and device volume.

Build Status Lint Contributors

TLDR

Control the device's volume with one line:

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
  1. 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.

  1. Define 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 to get a client ID and register your redirect URL (scheme).

Screenshot 2024-10-29 at 17 31 24

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: