Documentation
¶
Overview ¶
Package engine runs the go-librespot player inside the spotui process. It plays audio on this machine and shows up as a Spotify Connect device.
The go-librespot daemon normally takes commands over HTTP. Here it gets a channel-based server instead, so commands are plain method calls and events arrive on a Go channel.
Index ¶
- Constants
- Variables
- func LikedSongsURI(username string) string
- func Logout(statePath string) error
- func NewLogger(l *slog.Logger) librespot.Logger
- type AuthCode
- type Engine
- func (e *Engine) AdjustVolume(ctx context.Context, delta int32) error
- func (e *Engine) ContextTracks(ctx context.Context, uri string) (*daemon.ApiContextTracks, error)
- func (e *Engine) Events() <-chan any
- func (e *Engine) LibraryPlaylists(ctx context.Context) ([]daemon.ApiLibraryPlaylist, error)
- func (e *Engine) Next(ctx context.Context) error
- func (e *Engine) Play(ctx context.Context, uri, skipTo string) error
- func (e *Engine) PlayPause(ctx context.Context) error
- func (e *Engine) Prev(ctx context.Context) error
- func (e *Engine) Run(ctx context.Context)
- func (e *Engine) Seek(ctx context.Context, deltaMs int64) error
- func (e *Engine) SetRepeat(ctx context.Context, mode RepeatMode) error
- func (e *Engine) SetShuffle(ctx context.Context, on bool) error
- func (e *Engine) Status(ctx context.Context) (*daemon.ApiStatus, error)
- type Options
- type RepeatMode
- type Stopped
Constants ¶
const LevelTrace = slog.Level(-8)
LevelTrace is below slog's debug level. go-librespot logs every packet at this level.
Variables ¶
var ErrNotReady = errors.New("player is not ready")
ErrNotReady means the player did not take the request in time, usually because it is still logging in.
Functions ¶
func LikedSongsURI ¶
LikedSongsURI is the context URI of the user's Liked Songs.
Types ¶
type AuthCode ¶
AuthCode asks the user to approve the login. The engine sends it when no saved credentials exist. A nil URL means the login code is no longer needed.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine owns the embedded player.
func (*Engine) AdjustVolume ¶
AdjustVolume changes the volume by delta percent.
func (*Engine) ContextTracks ¶
ContextTracks lists the tracks of a playlist, album, artist, or Liked Songs URI. The list fills in over several calls: call again while Ready is false or Cached is less than Length.
func (*Engine) Events ¶
Events returns the channel of engine events: *daemon.ApiEvent, AuthCode, and Stopped values.
func (*Engine) LibraryPlaylists ¶
LibraryPlaylists returns the playlists in the user's library, including playlists the user follows but does not own.
func (*Engine) Play ¶
Play plays a track, album, playlist, or artist URI. If skipTo is set, the context starts at that track.
func (*Engine) Prev ¶
Prev goes to the previous track, or to the start of the current track if it has played for more than a few seconds.
func (*Engine) Run ¶
Run starts the player and blocks until ctx is cancelled. If the player stops because of an error, Run starts it again after a growing delay.
func (*Engine) SetRepeat ¶
func (e *Engine) SetRepeat(ctx context.Context, mode RepeatMode) error
SetRepeat sets the repeat mode.
func (*Engine) SetShuffle ¶
SetShuffle turns shuffle on or off for the current context.
type Options ¶
type Options struct {
DeviceName string
AudioBackend string
AudioDevice string
Bitrate int
InitialVolume int
StatePath string
Logger librespot.Logger
}
Options configures the engine.
type RepeatMode ¶
type RepeatMode int
RepeatMode is the repeat setting.
const ( RepeatOff RepeatMode = iota RepeatContext RepeatTrack )