player

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TRACK_TYPE   = "track"
	EPISODE_TYPE = "episode"
	AD_TYPE      = "ad"
	UNKNOWN_TYPE = "unknown"
)

Variables

This section is empty.

Functions

func GetDevices added in v0.2.0

func GetDevices(s *auth.Session) (*[]Device, error)

Retrieves currently available playback devices, or an empty slice if none are available.

Types

type Device added in v0.2.0

type Device struct {
	ID            string `json:"id"`
	IsActive      bool   `json:"is_active"`
	Name          string `json:"name"`
	Type          string `json:"type"`
	VolumePercent int    `json:"volume_percent"`
}

Device represents a spotify playback device. There is no guarantee that the device is still valid or active on the user's device since it will be cached.

type Player

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

func New

func New(c *config.Config) (*Player, error)

Creates a new player, getting device to any cached device or nil if no devices were found in cache.

func (*Player) Device added in v0.2.0

func (p *Player) Device() *Device

func (*Player) Pause

func (p *Player) Pause(s *auth.Session) error

Pauses playback on the current device.

func (*Player) Play

func (p *Player) Play(contextUri string, uri string, s *auth.Session) error

ContextUri can be the uri of an album or playlist. Uri should be a track contained in the album or playlist.

func (*Player) Resume

func (p *Player) Resume(s *auth.Session, play bool) error

Resume uses the "transfer playback device" endpoint instead of the "resume playback" to ensure playback is always transfered to selected device before the players resumes playback.

func (*Player) SeekToPosition

func (p *Player) SeekToPosition(s *auth.Session, pos int) error

Seeks to given position in milliseconds to user's current playing track.

func (*Player) SetDevice

func (p *Player) SetDevice(d *Device, c *config.Config) error

Sets the playback device for player and saves playback device into cache file "device.json".

func (*Player) SetVolume

func (p *Player) SetVolume(s *auth.Session, val int) error

Sets the player volume to a value between [0-100] percent.

func (*Player) Shuffle

func (p *Player) Shuffle(state bool, s *auth.Session) error

Enables or disables shuffling of tracks in current playlist or album.

func (*Player) SkipNext

func (p *Player) SkipNext(s *auth.Session) error

Skips the the next track in the queue.

func (*Player) SkipPrev

func (p *Player) SkipPrev(s *auth.Session) error

func (*Player) State

func (p *Player) State(s *auth.Session) (*PlayerState, error)

type PlayerState

type PlayerState struct {
	CurrentPlayingType string `json:"currently_playing_type"`

	Device       *Device `json:"device"`
	ProgressMs   int     `json:"progress_ms"`
	IsPlaying    bool    `json:"is_playing"`
	ShuffleState bool    `json:"shuffle_state"`

	// Each PlayerState will have either a nil track or episode,
	// depending on what the user is playing.
	Track   *spotify.Track
	Episode *spotify.Episode

	// Only used to retrieve the current item and
	// transfer into either a track or episode.
	Item interface{} `json:"item"`
}

Jump to

Keyboard shortcuts

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