librespot

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package librespot manages the lifecycle of an external librespot subprocess: spawning it with the configured bitrate, backend, and device name; watching stdout for connection/state events; piping PCM audio to the audio package when backend=="pipe"; and invoking user-supplied callbacks on reconnect and inactivity.

Process is the single orchestrator. Start launches the binary and begins log scanning; Stop sends SIGTERM and waits. OnReconnect fires after librespot re-registers with Spotify (used to transfer playback back to the preferred device); OnInactive fires when the device has been idle long enough that the UI may want to release it.

Index

Constants

View Source
const (
	DefaultBackend    = "pipe"
	DefaultDeviceName = "tuify"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BinaryPath string // path to librespot binary, default "librespot"
	DeviceName string // Spotify Connect device name, default DefaultDeviceName
	Bitrate    int    // 96, 160, or 320; default 320
	Backend    string // audio backend: DefaultBackend ("pipe"), "pulseaudio", etc.
	Username   string // Spotify username for direct auth (avoids zeroconf key issues)
	CacheDir   string // directory for librespot credential/audio cache
}

Config holds librespot launch parameters.

type Process

type Process struct {
	OnReconnect func()              // called when librespot authenticates (initial or restart)
	OnInactive  func()              // called when librespot reports device became inactive
	OnStdout    func(io.ReadCloser) // called with the stdout pipe in launch(); for pipe backend audio
	// contains filtered or unexported fields
}

Process manages a librespot child process with automatic restart on crash.

func NewProcess

func NewProcess(cfg Config) *Process

NewProcess creates a new Process with the given configuration.

func (*Process) Start

func (p *Process) Start() error

Start launches the librespot process. If the process crashes, it will be automatically restarted with backoff proportional to how quickly it died (2s–30s). The delay resets after 60 seconds of stable uptime.

func (*Process) Stop

func (p *Process) Stop() error

Stop sends SIGTERM, waits up to 5 seconds, then SIGKILL. Suppresses any pending or future automatic restarts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL