Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(src io.ReadCloser, format string) (io.ReadCloser, error)
- func NewPortAudioPlayer(provider SongProvider, notifier SongPlayNotifier) *portAudioPlayer
- type CommandFunc
- type Database
- type Handler
- type MPD
- type MpdError
- type Mux
- type Output
- type PlayerState
- type Playlist
- func (p *Playlist) Add(s Song, before int) int
- func (p *Playlist) ChangesPosID(w io.Writer, oldver int)
- func (p *Playlist) Clear()
- func (p *Playlist) Delete(r Range)
- func (p *Playlist) DeleteID(id int)
- func (p *Playlist) Find(w io.Writer, tag, needle string)
- func (p *Playlist) Info(w io.Writer)
- func (p *Playlist) InfoID(w io.Writer, id int)
- func (p *Playlist) InfoRange(w io.Writer, r Range)
- func (p *Playlist) Len() int
- func (p *Playlist) Move(from Range, to int)
- func (p *Playlist) MoveID(id, to int)
- func (p *Playlist) Next() SongFromPlaylist
- func (p *Playlist) PeekNext() SongFromPlaylist
- func (p *Playlist) Prev() SongFromPlaylist
- func (p *Playlist) Random() bool
- func (p *Playlist) Repeat() bool
- func (p *Playlist) SetCursor(idx int) SongFromPlaylist
- func (p *Playlist) SetCursorID(id int) SongFromPlaylist
- func (p *Playlist) SetRandom(state bool)
- func (p *Playlist) SetRepeat(state bool)
- func (p *Playlist) Swap(from, to int)
- func (p *Playlist) SwapID(id, to int)
- type Range
- type Server
- type Song
- type SongCallbackFunc
- type SongFromPlaylist
- type SongPlayNotifier
- type SongPlayedCallbackFunc
- type SongProvider
- type URLHandler
Constants ¶
const ( StateStop = iota StatePlay StatePause )
const ( MpdNotListErrorCode = 1 MpdArgErrorCode = 2 MpdPasswordErrorCode = 3 MpdPermissionErrorCode = 4 MpdUnknownCommandErrorCode = 5 MpdNoExistErrorCode = 50 MpdPlaylistMaxErrorCode = 51 MpdSystemErrorCode = 52 MpdPlaylistLoadErrorCode = 53 MpdUpdateAlreadyErrorCode = 54 MpdPlayerSyncErrorCode = 55 MpdExistErrorCode = 56 )
Standard MPD error codes.
Variables ¶
var ( // Common errors. ErrBadArgs = &MpdError{Code: MpdArgErrorCode, Message: "bad arguments"} ErrNoCommandGiven = &MpdError{Code: MpdUnknownCommandErrorCode, Message: "No command given"} ErrUnsupportedScheme = &MpdError{Code: MpdNoExistErrorCode, Message: "unsupported URL scheme"} )
Functions ¶
func Decode ¶
func Decode(src io.ReadCloser, format string) (io.ReadCloser, error)
Decode an io.Reader using avconv/ffmpeg.
func NewPortAudioPlayer ¶
func NewPortAudioPlayer(provider SongProvider, notifier SongPlayNotifier) *portAudioPlayer
Types ¶
type CommandFunc ¶
CommandFunc turns a function into a Handler.
type Database ¶
type Database interface { // Find an exact match for the query. Find(args []string) ([]Song, error) // Search the database with the given query. Search(args []string) ([]Song, error) }
Database is used to search for songs. Queries are encoded according to the MPD protocol, consisting of paired tag/query fields, and must be decoded by the implementation.
type Handler ¶
Objects implementing the Handler interface can be registered with a Mux to handle a particular MPD command. The command should do its own argument parsing (returning ErrBadArgs in case of errors), and write its output to the specified io.Writer.
type MPD ¶
type MPD struct { *Server // Tag types. Currently not used. TagTypes []string // contains filtered or unexported fields }
MPD server. Implements most of the commands of a real server, but it is oriented towards searching rather than browsing (that is to say, browsing is currently unimplemented).
func NewMPD ¶
func NewMPD(db Database, notifier SongPlayNotifier) *MPD
func (*MPD) HandleURL ¶
func (m *MPD) HandleURL(schema string, h URLHandler)
HandleURL installs a new URLHandler.
type MpdError ¶
An MPD error, with command details. Its Error method will return the error formatted according to the MPD protocol (an ACK reply).
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux is a multiplexer for MPD commands. Handlers can be registered to deal with specific commands.
func (*Mux) HandleFunc ¶
HandleFunc installs a new command handler (saving a cast to CommandFunc).
type PlayerState ¶
type PlayerState int
func (PlayerState) String ¶
func (s PlayerState) String() string
type Playlist ¶
type Playlist struct { Version int // contains filtered or unexported fields }
A Playlist contains an ordered list of songs, and a cursor.
func NewPlaylist ¶
func NewPlaylist() *Playlist
func (*Playlist) ChangesPosID ¶
ChangesPosID prints to w the difference between the specified playlist version and the current one, encoded in the differential format specified by the MPD protocol. At the moment, since playlist history is not supported, this function pretends that the playlist changed completely.
func (*Playlist) Next ¶
func (p *Playlist) Next() SongFromPlaylist
Next advances the cursor to the next song and returns it.
func (*Playlist) PeekNext ¶
func (p *Playlist) PeekNext() SongFromPlaylist
PeekNext looks at the next iteration of the cursor, but does not advance it.
func (*Playlist) Prev ¶
func (p *Playlist) Prev() SongFromPlaylist
Prev moves the cursor back to the previous song and returns it.
func (*Playlist) SetCursor ¶
func (p *Playlist) SetCursor(idx int) SongFromPlaylist
SetCursor moves the cursor to point at the specified song, and returns it.
func (*Playlist) SetCursorID ¶
func (p *Playlist) SetCursorID(id int) SongFromPlaylist
SetCursorID moves the cursor to point at the specified song (using its ID), and returns it.
type Range ¶
type Range struct {
Start, End int
}
Range represents a range of song indexes. The END item is not included in the range.
func ParseRange ¶
ParseRange parses a START:END integer range according to the MPD protocol spec. Note that in the MPD specification, the END element is included in the range.
type Server ¶
type Server struct { *Mux // contains filtered or unexported fields }
A server that speaks the MPD protocol.
func (*Server) ListenAndServe ¶
ListenAndServe starts the MPD server on the specified TCP address and runs our Mux to handle incoming commands.
type Song ¶
type Song interface { // URL returns a unique identifier for this song. URL() string // Info returns a string with the song metadata formatted // according to the MPD protocol. Info() string // Open the audio file and return it (in the original format, // which will be decoded by the player). The caller must call // Close() on the result. Open() (io.ReadCloser, error) Channels() int SampleRate() float64 Duration() int }
A song, with associated metadata and audio resource.
type SongCallbackFunc ¶
type SongCallbackFunc func() SongFromPlaylist
A function that returns the next song to be played.
type SongFromPlaylist ¶
type SongFromPlaylist interface { Song // ID returns the song id in the playlist. ID() int // Index of this song in the playlist. Index() int // Song returns the wrapped Song. GetSong() Song }
A song, with associated playlist information.
type SongPlayNotifier ¶
type SongPlayNotifier interface {
Notify(Song)
}
type SongPlayedCallbackFunc ¶
type SongPlayedCallbackFunc func(Song)
Callback called when a song has been successfully played in its entirety.
type SongProvider ¶
type SongProvider interface {
Next() SongFromPlaylist
}