Documentation ¶
Overview ¶
Package play implements a simple mp3 player. In general, to use this package first create a Player using NewPlayer, start a goroutine that listens for events on Player.Event, Load an mp3 using Player.Load, and play it using Player.Play(). GetMetadata can be used to retrieve ID3 information from mp3 files.
Index ¶
- Constants
- func DebugMetadata(filename string)
- func GetVolume() (volume byte, err error)
- func Play(filename string)
- func SetVolume(pct byte) (err error)
- func SetVolumeAll(pct byte) (err error)
- type Asc
- type Desc
- type Event
- type EventType
- type Info
- type Metadata
- type Player
- func (p Player) GetInfo() *Info
- func (p Player) GetStatus() PlayerStatus
- func (p Player) Load(filename string) (size int, err error)
- func (p Player) Pause()
- func (p Player) Play() (err error)
- func (p Player) Seek(offset int)
- func (p Player) SetRepeat(r bool)
- func (p Player) SetVolume(pct byte)
- func (p Player) SetVolumeAll(pct byte)
- func (p Player) Stop()
- type PlayerState
- type PlayerStatus
- type Queue
- type QueueElem
Constants ¶
const ( Move queueCmdType = iota MoveToTop Remove Clear )
Variables ¶
This section is empty.
Functions ¶
func DebugMetadata ¶
func DebugMetadata(filename string)
Print debugging information about the metadata in `filename` to stdout.
func SetVolume ¶
Set the volume as a percentage between 0 and 100 inclusive. This method sets the volume on the default ALSA card.
func SetVolumeAll ¶
Set the volume as a percentage between 0 and 100 inclusive. This method sets the volume on all ALSA cards.
Types ¶
type Event ¶
type Event struct { // Type is the type of event Type EventType // Data is the event data. // For OffsetChange, it is an int representing the offset. // For StateChange, it is a PlayerState. // For VolumeChange, it is a byte in the range 0-100 representing the volume. // For QueueChange, it is not set. // For Error, its an error. Data interface{} }
Event represents events sent by the Player.
type Info ¶
type Info struct { // The bitrate of the mp3, in kbps BitRate int // Sampling rate in Hz Rate int // Duration of mp3 in seconds (if available) or zero otherwise Duration float64 // Seconds per sample (if available) or zero otherwise Sps float64 }
Information about an mp3 determined once the mp3 is loaded.
type Metadata ¶
Metadata is information about an mp3 stored in id3 tags.
func GetMetadata ¶
GetMetadata extracts the id3 information from the mp3 file `filename`. For integer fields (like Tracknum) for which there is no data the field is set to -1.
type Player ¶
type Player struct { // Events is a channel to which Player events are written, such as state changes, volume changes, or offset changes. // When an event is recieved the user should call GetStatus() to get the current player information. Events chan Event // contains filtered or unexported fields }
Player is an mp3 player.
func (Player) GetInfo ¶
GetInfo returns an Info object about the loaded mp3. If an mp3 is not loaded, nil is returned
func (Player) Load ¶
Load the specified file into the Player. Call Play to play the file. Returns the size of the file in samples. On failure, err is non nil. On success, the player will write the current playing offset (in samples) to offchan periodically.
func (Player) Play ¶
Play the currently loaded file. The player must have an mp3 loaded and not currently playing.
func (Player) SetRepeat ¶
SetRepeat sets whether the track should be repeated when we reach the end or not.
func (Player) SetVolume ¶
SetVolume calls the regular SetVolume function but also writes a VolumeChange event to the Player's Event channel.
func (Player) SetVolumeAll ¶
SetVolumeAll calls the regular SetVolumeAll function but also writes a VolumeChange event to the Player's Event channel.
type PlayerState ¶
type PlayerState int
PlayerState represents the current state of a Player. Must be one of Empty, Playing, or Paused.
const ( // The player has no mp3 loaded Empty PlayerState = iota // The player has an mp3 loaded and is playing it Playing // The player has an mp3 loaded and it is paused Paused )
func (PlayerState) String ¶
func (s PlayerState) String() string
type PlayerStatus ¶
type PlayerStatus struct { // Offset is the offset within the current track in samples Offset int // Size of the current track in samples Size int // State of the Player State PlayerState // Volume Volume byte // Path to current mp3 Path string }
PlayerStatus contains information about the current status of the player
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue implements a queue of metadata for a player. Items from the queue are added to the player when the player is Empty.
func NewQueueWithEvents ¶
func (Queue) Move ¶
Move moves the specified queue element `index` by `delta`. Currently only -1 and +1 are supported for delta.