player

package
v0.0.0-...-a380f54 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: BSD-2-Clause Imports: 6 Imported by: 2

Documentation

Overview

Package player defines types and methods for defining a Tchaik player.

Index

Constants

View Source
const (
	ActionPlay            Action = "play"
	ActionPause                  = "pause"
	ActionNext                   = "next"
	ActionPrev                   = "prev"
	ActionTogglePlayPause        = "togglePlayPause"
	ActionToggleRepeat           = "toggleRepeat"
	ActionToggleMute             = "toggleMute"
)

Actions which don't need values.

View Source
const (
	ActionSetVolume Action = "setVolume"
	ActionSetMute          = "setMute"
	ActionSetRepeat        = "setRepeat"
	ActionSetTime          = "setTime"
)

Player actions which require values.

Variables

View Source
var RepActions = map[Action]string{
	ActionPlay:            "PLAY",
	ActionPause:           "PAUSE",
	ActionNext:            "NEXT",
	ActionPrev:            "PREV",
	ActionTogglePlayPause: "TOGGLE_PLAY_PAUSE",
	ActionToggleRepeat:    "TOGGLE_REPEAT",
	ActionToggleMute:      "TOGGLE_MUTE",

	ActionSetVolume: "SET_VOLUME",
	ActionSetMute:   "SET_MUTE",
	ActionSetRepeat: "SET_REPEAT",
	ActionSetTime:   "SET_TIME",
}

Functions

func NewHTTPHandler

func NewHTTPHandler(p *Players) http.Handler

NewHTTPHandler returns an http.Handler which defines a REST API for interacting with Players.

Types

type Action

type Action string

Action is a type which represents an enumeration of available player actions.

func RepActionToAction

func RepActionToAction(a string) (Action, bool)

RepActionToAction takes a string and returns an Action and true if the string represents a valid action, or Action("") and false otherwise. TODO(dhowden): This seems quite clunky??

type InvalidActionError

type InvalidActionError string

InvalidActionError is an error returned when an invalid action has been received.

func (InvalidActionError) Error

func (i InvalidActionError) Error() string

type InvalidValueError

type InvalidValueError string

InvalidValueError is an error returned by value-setting methods.

func (InvalidValueError) Error

func (v InvalidValueError) Error() string

Error implements error.

type Player

type Player interface {
	// Key returns a unique identifier for this Player.
	Key() string

	// Do sends a Action to the player.
	Do(a Action) error

	// SetMute enabled/disables mute.
	SetMute(bool) error
	// SetRepeat enable/disables a repeat of the current track.
	SetRepeat(bool) error
	// SetVolume sets the volume (value should be between 0.0 and 1.0).
	SetVolume(float64) error
	// SetTime sets the current play position
	SetTime(float64) error
}

Player is an interface which defines methods for controlling a player.

func Multi

func Multi(key string, players ...Player) Player

Multi returns a Player that will apply calls to all provided Players in sequence. If an error is returning by a Player then it is returned immediately.

func NewRep

func NewRep(key string, fn RepFn) Player

NewRep creates a Player p which will call fn with a standardised representation for each call to methods of p (eee RepActions for the Action mapping). FIXME: this is possibly a unhelpful and overly generic mess.

func Validated

func Validated(p Player) Player

Validated wraps a player with validation checks for value-setting methods.

type Players

type Players struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Players is a collection of players which are identified by key.

func NewPlayers

func NewPlayers() *Players

NewPlayers creates a Players.

func (*Players) Add

func (s *Players) Add(p Player)

Add the Player to the Players.

func (*Players) Get

func (s *Players) Get(key string) Player

Get the Player identified by the key.

func (*Players) List

func (s *Players) List() []string

List all Player keys in Players.

func (*Players) MarshalJSON

func (s *Players) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Players) Remove

func (s *Players) Remove(key string)

Remove the Player from Players (by key).

type RepAction

type RepAction struct {
	Action string      `json:"action"`
	Value  interface{} `json:",omitempty"`
}

RepAction is a representation of a player action as it would be transmitted.

func (RepAction) Apply

func (r RepAction) Apply(p Player) (err error)

Apply applies the action in RepAction to the Player.

type RepFn

type RepFn func(interface{})

RepFn is a type which represents a command function which will be called with a standardised command structure when Player methods are used.

Jump to

Keyboard shortcuts

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