player

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnitialized error = errors.New("mpv player uninitialized")

Error returned by many Player functions if called before the player has not been initialized.

Functions

This section is empty.

Types

type AudioDevice

type AudioDevice struct {
	// The name of the audio device.
	// This is the string to pass to SetAudioDevice.
	Name string

	// The description of the audio device.
	// This is the friendly string that should be used in UIs.
	Description string
}

Information about a specific audio device. Returned by ListAudioDevices.

type Equalizer added in v0.4.0

type Equalizer interface {
	IsEnabled() bool
	Preamp() float64
	Curve() EqualizerCurve
	Type() string
	// Returns the band frequencies as strings friendly for display
	BandFrequencies() []string
}

type EqualizerBand added in v0.4.0

type EqualizerBand struct {
	Frequency int
	Gain      float64
	Width     float64
	WidthType WidthType
}

func (EqualizerBand) String added in v0.4.0

func (e EqualizerBand) String() string

type EqualizerCurve added in v0.4.0

type EqualizerCurve []EqualizerBand

func (EqualizerCurve) String added in v0.4.0

func (e EqualizerCurve) String() string

type ISO15BandEqualizer added in v0.4.0

type ISO15BandEqualizer struct {
	Disabled  bool
	EQPreamp  float64
	BandGains [15]float64
}

func (*ISO15BandEqualizer) BandFrequencies added in v0.4.0

func (*ISO15BandEqualizer) BandFrequencies() []string

func (*ISO15BandEqualizer) Curve added in v0.4.0

func (*ISO15BandEqualizer) IsEnabled added in v0.4.0

func (i *ISO15BandEqualizer) IsEnabled() bool

func (*ISO15BandEqualizer) Preamp added in v0.4.0

func (i *ISO15BandEqualizer) Preamp() float64

func (*ISO15BandEqualizer) Type added in v0.4.0

func (*ISO15BandEqualizer) Type() string

type LoopMode added in v0.4.0

type LoopMode int

The playback loop mode (LoopNone, LoopAll, LoopOne).

const (
	LoopNone LoopMode = iota
	LoopAll
	LoopOne
)

func (LoopMode) String added in v0.4.0

func (l LoopMode) String() string

type MediaInfo added in v0.4.0

type MediaInfo struct {
	// The sample format as string. This uses the same names as used in other places of mpv.
	// NOTE: this is the format that the decoder outputs, NOT necessarily the format of the file.
	Format string

	// Audio samplerate.
	Samplerate int

	// The number of channels.
	ChannelCount int

	// The audio codec.
	Codec string

	// The average bit rate in bits per second.
	Bitrate int
}

Media information about the currently playing media.

type Player

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

Player encapsulates the mpv instance and provides functions to control it and to check its status.

func New

func New() *Player

Returns a new player. Must call Init on the player before it is ready for playback.

func NewWithClientName

func NewWithClientName(c string) *Player

Same as New, but sets the application name that mpv reports to the system audio API.

func (*Player) AppendFile

func (p *Player) AppendFile(url string) error

Appends the given file to the play queue. Note that the Player API does not provide methods to read the play queue. Clients are expected to maintain their own play queue model.

func (*Player) ClearPlayQueue

func (p *Player) ClearPlayQueue() error

Clears the play queue, except for the currently playing file.

func (*Player) Destroy

func (p *Player) Destroy()

Destroy the player.

func (*Player) Equalizer added in v0.4.0

func (p *Player) Equalizer() Equalizer

func (*Player) GetLoopMode added in v0.4.0

func (p *Player) GetLoopMode() LoopMode

Get the loop mode of the player.

func (*Player) GetMediaInfo added in v0.4.0

func (p *Player) GetMediaInfo() (MediaInfo, error)

func (*Player) GetStatus

func (p *Player) GetStatus() Status

Get the current status of the player.

func (*Player) GetVolume

func (p *Player) GetVolume() int

Gets the current volume of the player.

func (*Player) Init

func (p *Player) Init(maxCacheMB int) error

Initializes the Player and makes it ready for playback. Most Player functions will return ErrUnitialized if called before Init.

func (*Player) IsSeeking

func (p *Player) IsSeeking() bool

Returns true if a seek is currently in progress.

func (*Player) ListAudioDevices

func (p *Player) ListAudioDevices() ([]AudioDevice, error)

List available audio devices.

func (*Player) OnPaused

func (p *Player) OnPaused(cb func())

Registers a callback which is invoked when the player transitions to the Paused state.

func (*Player) OnPlaying

func (p *Player) OnPlaying(cb func())

Registers a callback which is invoked when the player transitions to the Playing state.

func (*Player) OnSeek

func (p *Player) OnSeek(cb func())

Registers a callback which is invoked whenever a seek event occurs.

func (*Player) OnStopped

func (p *Player) OnStopped(cb func())

Registers a callback which is invoked when the player transitions to the Stopped state.

func (*Player) OnTrackChange

func (p *Player) OnTrackChange(cb func(int64))

Registers a callback which is invoked when the currently playing track changes, or when playback begins at any time from the Stopped state. Callback is invoked with the index of the currently playing track (zero-based).

func (*Player) PlayFile

func (p *Player) PlayFile(url string) error

Plays the specified file, clearing the previous play queue, if any.

func (*Player) PlayFromBeginning

func (p *Player) PlayFromBeginning() error

Start playback from the first track in the play queue.

func (*Player) PlayPause

func (p *Player) PlayPause() error

Begins playback if there is anything in the play queue and player is stopped or paused. If player is playing, pauses playback.

func (*Player) PlayTrackAt

func (p *Player) PlayTrackAt(idx int) error

Start playback from the specified track index in the play queue.

func (*Player) RemoveTrackAt

func (p *Player) RemoveTrackAt(idx int) error

Removes the item at the given index from the internal playqueue.

func (*Player) Seek

func (p *Player) Seek(target string, mode SeekMode) error

Seeks within the currently playing track. See MPV seek command documentation for more details.

func (*Player) SeekBackOrPrevious

func (p *Player) SeekBackOrPrevious() error

Seeks to the beginning of the current track if:

  • The current track is the first track in the play queue, or
  • The current time is more than 3 seconds past the beginning of the track.

Else seeks to the beginning of the previous track.

func (*Player) SeekNext

func (p *Player) SeekNext() error

Seeks to the next track in the play queue, if any.

func (*Player) SetAudioDevice

func (p *Player) SetAudioDevice(deviceName string) error

func (*Player) SetAudioExclusive

func (p *Player) SetAudioExclusive(tf bool)

Sets the audio exclusive option of the player. Unlike most Player functions, SetAudioExclusive can be called before Init, to set the initial option of the player on startup.

func (*Player) SetEqualizer added in v0.4.0

func (p *Player) SetEqualizer(eq Equalizer) error

func (*Player) SetLoopMode added in v0.4.0

func (p *Player) SetLoopMode(mode LoopMode) error

Set the loop mode of the player.

func (*Player) SetNextLoopMode added in v0.4.0

func (p *Player) SetNextLoopMode() error

Change the loop mode of the player to the next one. Useful for toggling UI elements, to change modes without knowing the current player mode.

func (*Player) SetReplayGainOptions

func (p *Player) SetReplayGainOptions(options ReplayGainOptions) error

Sets the ReplayGain options of the player. Unlike most Player functions, SetReplayGainOptions can be called before Init, to set the initial replaygain options of the player on startup.

func (*Player) SetVolume

func (p *Player) SetVolume(vol int) error

Sets the volume of the player (0-100). Unlike most Player functions, SetVolume can be called before Init, to set the initial volume of the player on startup.

func (*Player) Stop

func (p *Player) Stop() error

Stops playback and clears the play queue.

type ReplayGainMode

type ReplayGainMode string

One of "no", "track", or "album"

const (
	ReplayGainNone  ReplayGainMode = "no"
	ReplayGainTrack ReplayGainMode = "track"
	ReplayGainAlbum ReplayGainMode = "album"
)

type ReplayGainOptions

type ReplayGainOptions struct {
	Mode            ReplayGainMode
	PreampGain      float64
	PreventClipping bool
}

Replay Gain options (argument to SetReplayGainOptions).

type SeekMode

type SeekMode int

Argument to Seek function (SeekAbsolute, SeekRelative, SeekAbsolutePercent, SeekRelativePercent).

const (
	SeekAbsolute SeekMode = iota
	SeekRelative
	SeekAbsolutePercent
	SeekRelativePercent
)

func (SeekMode) String

func (s SeekMode) String() string

type State

type State int

The playback state (Stopped, Paused, or Playing).

const (
	Stopped State = iota
	Paused
	Playing
)

type Status

type Status struct {
	State       State
	TimePos     float64
	Duration    float64
	PlaylistPos int64
}

The current status of the player. Includes playback state, current time, total track time, and playlist position.

type WidthType added in v0.4.0

type WidthType int
const (
	WidthTypeHz WidthType = iota
	WidthTypeKhz
	WidthTypeQ
	WidthTypeOctave
	WidthTypeSlope
)

func (WidthType) String added in v0.4.0

func (w WidthType) String() string

Jump to

Keyboard shortcuts

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