Media player integration
Connect a third-party music player to Droppy's built-in Music widget, Floating Liquid Player, Lock Screen Expanded Stage, Lyrics, and iPhone/Android Companion app.
A droplet that adopts MediaPlayerIntegrating does not need to build its own player UI. Instead, declare your player's bundle identifier(s) and capabilities in mediaPlayerDescriptor, publish state snapshots through mediaPlayerState, and handle callbacks for favorite, shuffle, repeat, Playing Next queue, custom transport, or lyrics.
Declare minAPI 1.31.0 in droplet.json and request "media-read" (passive observation, queue, lyrics, now-playing feed) and "media-transport" (favorite, shuffle, repeat, queue jump/promote, custom transport).
import Combine
import DroppyKit
import Foundation
@MainActor
final class SonoraDroplet: Droplet, MediaPlayerIntegrating {
static let id = DropletID("sonora")
private let stateSubject = CurrentValueSubject<DropletMediaPlayerState, Never>(.empty)
var mediaPlayerDescriptor: DropletMediaPlayerDescriptor {
DropletMediaPlayerDescriptor(
displayName: "Sonora",
bundleIdentifiers: ["app.sonora.player"],
capabilities: [
.favorite,
.shuffle,
.repeatMode,
.repeatOne,
.queue,
.queuePlayItem,
.queuePromoteNext,
.customTransport,
.lyrics
],
accentColor: DropletMediaAccentColor(red: 0.94, green: 0.34, blue: 0.42),
favoriteStyle: .heart,
symbolName: "music.note"
)
}
var mediaPlayerState: AnyPublisher<DropletMediaPlayerState, Never> {
stateSubject.eraseToAnyPublisher()
}
func activate(host: DropletHost) {
// Connect to Sonora's local bridge or IPC channel.
}
func deactivate() {
// Disconnect and release timers/sockets.
}
func mediaSessionDidActivate(bundleIdentifier: String) {
refreshQueue()
}
func trackDidChange(_ track: DropletMediaTrack) {
refreshQueue()
}
func toggleFavorite() {
let next = !stateSubject.value.isFavorite
setFavorite(next)
}
func setFavorite(_ isFavorite: Bool) {
// Send update to Sonora and publish the new state.
}
func toggleShuffle() {
setShuffle(!stateSubject.value.isShuffleEnabled)
}
func setShuffle(_ isEnabled: Bool) {
// Send shuffle update to Sonora and publish the new state.
}
func cycleRepeatMode() {
let next: DropletMediaRepeatMode = switch stateSubject.value.repeatMode {
case .off: .all
case .all: .one
case .one: .off
}
setRepeatMode(next)
}
func setRepeatMode(_ mode: DropletMediaRepeatMode) {
// Send repeat mode update to Sonora and publish the new state.
}
func refreshQueue() {
// Fetch upcoming rows and emit via stateSubject.
}
func playQueueItem(id: String) {
// Ask Sonora to jump to the matching queued track.
}
func promoteQueueItemToNext(id: String) {
// Ask Sonora to move the matching queued track next.
}
func performMediaTransport(_ command: DropletMediaTransportCommand) -> Bool {
// Return true if Sonora handled the command directly, or false to let
// Droppy fall back to MediaRemote.
return false
}
func fetchLyrics(for track: DropletMediaTrack) async -> DropletMediaLyrics? {
// Return .lrc(...), .synced(...), or .plain(...), or nil to let Droppy
// fall back to LRCLIB.
return nil
}
}Capabilities and manifest gating
Droppy enforces manifest permissions automatically:
- Passive integration (reading state, displaying Playing Next queue, supplying lyrics, or pushing
.nowPlayingFeedupdates) requires"media-read"or"media-transport"indroplet.json. - Any write or playback-control capability (
.favorite,.shuffle,.repeatMode,.repeatOne,.queuePlayItem,.queuePromoteNext,.customTransport) requires"media-transport". If a droplet omits"media-transport", Droppy strips mutating capabilities and ignores write requests.
Built-in player firewall and resource limits
- Built-in players (Apple Music, Spotify, Kaset, Apple TV, and Droppy itself) are reserved and cannot be claimed by droplets.
- A droplet may claim at most 16 normalized bundle identifiers. If two droplets claim the same bundle identifier, Droppy assigns ownership deterministically to the lexicographically lowest droplet ID.
- Queues are capped at 25 rows. Inline
artworkDatais capped at 2 MB and decoded off the main thread into a bounded cache. - Artwork URLs must use
https,file, or loopbackhttp(127.0.0.1,localhost,::1). - Lyrics requests time out after 5 seconds; raw LRC text is capped at 256 KB and parsed/plain lyrics are capped at 1,000 lines.
MediaPlayerIntegratingDropletMediaPlayerDescriptorDropletMediaCapabilitiesDropletMediaPlayerStateDropletMediaFavoriteStyleDropletMediaRepeatModeDropletMediaAccentColorDropletMediaTrackDropletMediaQueueItemDropletMediaNowPlayingDropletMediaTransportCommandDropletMediaLyricLineDropletMediaLyrics