Documentation ¶
Index ¶
- Constants
- Variables
- func AskForPassword() ([]byte, error)
- func AskForServer() string
- func AskForUsername() string
- func RefreshLibrary(db MusicStore, provider Provider) error
- type Album
- type Artist
- type AuthStore
- type CallbackData
- type CredentialRequest
- type CredentialRequester
- type LogLevel
- type Logger
- func (l *Logger) DebugLog(logLine string)
- func (l *Logger) ErrorLog(logLine string)
- func (l *Logger) InfoLog(logLine string)
- func (l *Logger) RemoveChild(child *Logger)
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SubLogger(prefix string) *Logger
- type MusicProvider
- type MusicStore
- type Player
- func (p *Player) Close()
- func (p *Player) CreatePlayQueue(tracks []*Track)
- func (p *Player) CurrentTrack() *Track
- func (p *Player) GetCurrentState() State
- func (p *Player) Next()
- func (p *Player) NextTrack() *Track
- func (p *Player) Pause()
- func (p *Player) Play()
- func (p *Player) Previous()
- func (p *Player) Stop()
- func (p *Player) UpdateProvider(c Provider)
- type Playlist
- type PlaylistEntry
- type Provider
- type State
- type StreamHandler
- type Track
Constants ¶
const Version string = "0.9.0"
Version represents the application version using SemVer
Variables ¶
var BufferingWait = time.Duration(200 * time.Millisecond)
BufferingWait is the time in milliseconds to wait on reading from the network socket before playing the track. If this is to low, an EOF can be returned when reading from the memory buffer causing the track from being skipped. Default value is 200 ms.
var DefaultCredentialRequest = &CredentialRequest{}
DefaultCredentialRequest is a default credential requester. It will read the info from stdin.
var ( // ErrNoCredentialsStored is returned if the backend does not have any // credentials stored. ErrNoCredentialsStored = errors.New("No credentials stored") )
var ( // ErrNoNextTrack is returned when the playing queue does not have a track to play // but is asked to play one. ErrNoNextTrack = errors.New("no track in playing queue") )
var MaxReadRetryAttempts = 5
MaxReadRetryAttempts is the number of retries when a EOF is returned during the first read.
Functions ¶
func AskForPassword ¶
func AskForServer ¶
func AskForServer() string
func AskForUsername ¶
func AskForUsername() string
func RefreshLibrary ¶
func RefreshLibrary(db MusicStore, provider Provider) error
Types ¶
type Album ¶
type Album struct { // Name is the album name Name string // Artist is the name of the artist for this album. Artist string // Year is the year the album was released. Year uint32 // ID is the ID for the album. ID string // Tracks is an array of all the tracks. Tracks []*Track }
Album holds all data for an album.
type Artist ¶
type Artist struct { // Name of the artist. Name string // ID for the artist. ID string // Albums is an array of all the artist's albums. Albums []*Album }
Artist holds all the data for an artist.
type AuthStore ¶
type AuthStore interface { // GetCredentials gets the credentials from the database. GetCredentials(key []byte) ([]byte, error) // SaveCredentials saves the credentials to the database. SaveCredentials(key []byte, credStruct []byte) error }
AuthStore is the interface for databases which handles credentials.
type CallbackData ¶ added in v0.8.0
type CallbackData struct { // CurrentTrack is the track being played. CurrentTrack *Track // Duration is how long the current track has been played. Duration time.Duration }
CallbackData is passed in to the player's callback function. It holds current values from right before the callback function was called.
type CredentialRequest ¶
type CredentialRequest struct{}
func (*CredentialRequest) GetPassword ¶
func (c *CredentialRequest) GetPassword() string
GetPassword asks the user to enter the password via stdin.
func (*CredentialRequest) GetServer ¶
func (c *CredentialRequest) GetServer() string
GetServer asks the user to enter the server url via stdin.
func (*CredentialRequest) GetUsername ¶
func (c *CredentialRequest) GetUsername() string
GetUsername asks the user to enter the username via stdin.
type CredentialRequester ¶
type CredentialRequester interface { // GetServer should return the server url. GetServer() string // GetUsername should return the username gotten from the user. GetUsername() string // GetPassword should return the password gotten from the user. GetPassword() string }
CredentialRequester is an interface for getting credentials from the user.
type LogLevel ¶ added in v0.9.0
type LogLevel int8
LogLevel is used to determine which logs are written to the writer. The logger will write log types of the set level or lower. For example if the level is set at InfoLevel, info and error logs will be written to the writer but debug logs will not.
type Logger ¶ added in v0.9.0
type Logger struct {
// contains filtered or unexported fields
}
Logger instance can be used to log messages to the user. Each parent logger keep tracks of its children logs.
func DefaultLogger ¶ added in v0.9.0
func DefaultLogger() *Logger
DefaultLogger returns a Logger instance that logs to STDERR.
func NewLogger ¶ added in v0.9.0
NewLogger creates a new Logger instance that will log to the given io.Writer.
func (*Logger) RemoveChild ¶ added in v0.9.0
RemoveChild tells the Logger to stop tracking the child logger.
type MusicProvider ¶
type MusicProvider int
MusicProvider is the provider identifier.
const ( // GooglePlayMusic is used as an identifier for the GPM provider. GooglePlayMusic MusicProvider = iota // SubSonic us used as an identifier for the subsonic provider. SubSonic )
type MusicStore ¶
type MusicStore interface { // AddTracks stores the tracks to the database. This methods is // deprecated and should not be used by new implementations. AddTracks([]*Track) error // AddPlaylists stores the playlists to the database. This methods is // deprecated and should not be used by new implementations. AddPlaylists(Provider, []*Playlist, []*PlaylistEntry) error // Artists returns the stored artists from the database. Artists() ([]*Artist, error) // SaveArtists saves the artists to the database. SaveArtists(artists []*Artist) error }
MusicStore is the interface for databases which stores library caches.
type Player ¶ added in v0.8.0
type Player struct { // Error returns errors from the handler and the provider. Error chan error // contains filtered or unexported fields }
Player is the mp3 player struct. This struct handles all player actions.
func NewPlayer ¶ added in v0.8.0
func NewPlayer(l *Logger, p Provider, h StreamHandler, callback func(*CallbackData), interval int) *Player
NewPlayer returns a new Player. The Provider should be a music provider. The callback is a function that is called every interval by the Player as long as the state is not stopped. If interval is set to 0, the callback will be called every 1000 ms. The callback function can be used to update the UI with current play status etc.
func (*Player) CreatePlayQueue ¶ added in v0.8.0
CreatePlayQueue creates a new list with queued tracks.
func (*Player) CurrentTrack ¶ added in v0.8.0
CurrentTrack returns the current playing or paused track.
func (*Player) GetCurrentState ¶ added in v0.8.0
GetCurrentState returns the player's current internal state.
func (*Player) Next ¶ added in v0.8.0
func (p *Player) Next()
Next skips to the next track in the play queue.
func (*Player) Pause ¶ added in v0.8.0
func (p *Player) Pause()
Pause pauses or resumes playing a track.
func (*Player) Play ¶ added in v0.8.0
func (p *Player) Play()
Play starts or resumes playing the track first in the play queue.
func (*Player) Previous ¶ added in v0.8.0
func (p *Player) Previous()
Previous will go back to previous played track.
func (*Player) Stop ¶ added in v0.8.0
func (p *Player) Stop()
Stop should be called to stop playing the track.
func (*Player) UpdateProvider ¶ added in v0.8.0
UpdateProvider sets a new provider for the player. It stops the current playing track and restart the player.
type Playlist ¶
type Playlist struct { // ID is the playlist's ID. ID string // Name is the name of the playlist. Name string }
Playlist is a playlist structure.
type PlaylistEntry ¶
type PlaylistEntry struct { // PlaylistId is the ID of the playlist. PlaylistId string // TrackId is the ID of the track. TrackId string }
PlaylistEntry represents an entry in a playlist.
type Provider ¶
type Provider interface { // ListTracks returns all the tracks from the provider. [DEPRECATED] ListTracks() ([]*Track, error) // FetchLibrary gets the library from the server. This implementation // should be used instead of the old implementations. FetchLibrary() ([]*Artist, error) // GetTrackInfo returns information abot the track from the provider. GetTrackInfo(trackID string) (*Track, error) // GetStream returns a ReadCloser stream of the track. The stream // has to be a MP3 encoded stream. [DEPRECATED] GetStream(songID string) (io.ReadCloser, error) // ListPlaylists returns all the playlists from the provider. ListPlaylists() ([]*Playlist, error) // ListPlaylistEntries returns to entries in the playlist. [DEPRECATED] ListPlaylistEntries() ([]*PlaylistEntry, error) // GetProvider returns the MusicProvider type. GetProvider() MusicProvider }
Provider is a music provider.
type StreamHandler ¶ added in v0.8.0
type StreamHandler interface { // Finished should return a chan that is used to signal to the Player when the // track has been processed. The Player will call Play with a Reader for the next track // in the queue if one exists or call Stop if it was the final track in the playing queue. Finished() <-chan struct{} // Play is called with an io.Reader for the track. The handler should decode the stream and // send it to an output writer. Play(io.Reader) error // Stop is called by the Player to signal that all processing should stop. It is recommended that // output writers is closed when this is called. Stop() // Pause is called when stream processing should be paused. Pause() // Continue is called when stream processing should be resumed after it has been paused. Continue() // Errors returns a channel with errors from the handler. All read and write errors not handled // by the stream handler is sent to this channel. The controller must listen to this channel or // the handler might hang. Errors() <-chan error }
StreamHandler should handle streams for the player. It should take an io.Reader and do the decoding to play the track.
type Track ¶
type Track struct { // Artist is the name of the artist. Artist string // Album is the album. Album string // AlbumArtist is the album artist. AlbumArtist string // DiscNumber is the disc number for the track. DiscNumber uint8 // TrackNumber is the track number for the track. TrackNumber uint32 // DurationMillis is the song length in milliseconds. DurationMillis string // EstimatedSize is the estimated size for the track. EstimatedSize string // ID is the tracks unique ID. ID string // PlayCount is how many times to track has been played. PlayCount uint32 // Title is the song title. Title string // Year is the year the track was released. Year uint32 }
Track is a common structure from a music track.