player

package
v0.12.8 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: GPL-3.0 Imports: 11 Imported by: 3

Documentation

Overview

Package player provides a generic interface to play music from a github.com/frizinak/libym/collection.Queue.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("backend is not available, you will need to compile from source")

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Play should play the given string (file or url)
	// and send once on done to signal EOF.
	Play(string) (done chan struct{}, error error)

	// Paused must report if the player is paused.
	Paused() bool

	// Pause must pause the player.
	Pause(bool)

	// TogglePause should toggle the paused status.
	TogglePause()

	// SetVolume must update the player volume. argument is always
	// between 0 and 1.
	SetVolume(float64)

	// Increase volume should change the volume by the given delta.
	IncreaseVolume(float64)

	// Volume must report the current volume.
	Volume() float64

	// Seek must seek to the given duration if whence == io.SeekStart and
	// Do a relative seek if whence == io.SeekCurrent.
	Seek(d time.Duration, whence int)

	// Seek must seek to the given position. argument is always
	// between 0 and 1.
	SeekTo(float64)

	// Position must report the current position in the file.
	Position() time.Duration

	// Position must report the total file duration.
	Duration() time.Duration

	// Stop must stop playing.
	Stop()

	// Close should release as many resources as possible as the Backend
	// wont be used any more.
	Close() error
}

Backend is the grittier interface to an actual music player.

type ErrorReporter

type ErrorReporter interface {
	Err(error)
}

ErrorReporter should log errors.

type Player

type Player struct {
	// contains filtered or unexported fields
}

Player provides an interface to play songs from a collection.Queue given a Backend.

func NewPlayer

func NewPlayer(backend Backend, reporter ErrorReporter, queue *collection.Queue, posFile string) *Player

NewPlayer constructs a new player.

func (*Player) Close

func (p *Player) Close() error

Close releases resources and this player-backend pair should not be used anymore.

func (*Player) Duration

func (p *Player) Duration() time.Duration

Duration returns the estimated duration of the current file.

func (*Player) ForcePlay

func (p *Player) ForcePlay()

ForcePlay as opposed to play, restarts playback of the active queue item. e.g.: if song A is currently playing and the active queue item is set to item B, B would be start after A is done playing. ForcePlay stops A and starts B.

func (*Player) IncreaseVolume

func (p *Player) IncreaseVolume(n float64)

IncreaseVolume changes the volume by the given delta (-1-1).

func (*Player) LoadPosition added in v0.9.0

func (p *Player) LoadPosition() error

func (*Player) Next

func (p *Player) Next()

Next plays the next song in the queue

func (*Player) Pause

func (p *Player) Pause()

Pause pauses the player.

func (*Player) Paused

func (p *Player) Paused() bool

Paused reports the paused state.

func (*Player) Play

func (p *Player) Play()

Play starts playback if nothing was playing or the player was paused.

func (*Player) Position

func (p *Player) Position() time.Duration

Position reports the current position in the file.

func (*Player) Prev

func (p *Player) Prev()

Prev plays the previous song in the queue

func (*Player) SavePosition added in v0.9.0

func (p *Player) SavePosition() error

func (*Player) Seek

func (p *Player) Seek(n time.Duration, whence int)

Seek seeks in the current file. whence == io.SeekStart: absolute seek whence == io.SeekCurrent: relative seek

func (*Player) SeekTo

func (p *Player) SeekTo(n float64)

SeekTo seeks to a percentage in the current file (0-1).

func (*Player) SetVolume

func (p *Player) SetVolume(n float64)

SetVolume sets the Backend volume to the given value (0-1).

func (*Player) Volume

func (p *Player) Volume() float64

Volume returns the current volume (0-1).

type UnsupportedBackend

type UnsupportedBackend struct{}

func (UnsupportedBackend) Close

func (u UnsupportedBackend) Close() error

func (UnsupportedBackend) Duration

func (u UnsupportedBackend) Duration() time.Duration

func (UnsupportedBackend) IncreaseVolume

func (u UnsupportedBackend) IncreaseVolume(n float64)

func (UnsupportedBackend) Init

func (u UnsupportedBackend) Init() error

func (UnsupportedBackend) Pause

func (u UnsupportedBackend) Pause(bool)

func (UnsupportedBackend) Paused

func (u UnsupportedBackend) Paused() bool

func (UnsupportedBackend) Play

func (u UnsupportedBackend) Play(string) (chan struct{}, error)

func (UnsupportedBackend) Position

func (u UnsupportedBackend) Position() time.Duration

func (UnsupportedBackend) Seek

func (UnsupportedBackend) SeekTo

func (u UnsupportedBackend) SeekTo(float64)

func (UnsupportedBackend) SetVolume

func (u UnsupportedBackend) SetVolume(float64)

func (UnsupportedBackend) Stop

func (u UnsupportedBackend) Stop()

func (UnsupportedBackend) TogglePause

func (u UnsupportedBackend) TogglePause()

func (UnsupportedBackend) Volume

func (u UnsupportedBackend) Volume() float64

Jump to

Keyboard shortcuts

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