player

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MinMax

func MinMax(array []float64) (float64, float64)

Types

type PlaySession

type PlaySession struct {
}

type Player

type Player struct {
	Queue *Queue

	Guild   string
	Conf    *models.Conf
	Storage *storage.StormDB

	Stats *Stats
	// contains filtered or unexported fields
}

Player is the struct in charge of connecting to voice channels and streaming tracks to them.

func NewPlayer

func NewPlayer(s *discordgo.Session, conf *cmd.Conf, log zerolog.Logger, guildID string, storage *storage.StormDB, gc *models.Conf) (*Player, error)

NewPlayer will create a new player from scratch using the provided arguments

func (*Player) Connect

func (p *Player) Connect() error

Connect will connect the player to the voice channel.

func (*Player) Disconnect

func (p *Player) Disconnect() error

Disconnect will disconnect the player from the currently connected voice channel if any.

func (*Player) GenerateNowPlayingEmbed

func (p *Player) GenerateNowPlayingEmbed(short bool) *discordgo.MessageEmbed

func (*Player) GeneratePlayerString

func (p *Player) GeneratePlayerString(dur time.Duration) string

func (*Player) Kill

func (p *Player) Kill()

func (*Player) Pause

func (p *Player) Pause()

Pause will pause an ongoing stream

func (*Player) Paused

func (p *Player) Paused() bool

func (*Player) Play

func (p *Player) Play()

Play will start to play the current queue

func (*Player) Playing

func (p *Player) Playing() bool

func (*Player) Read

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

func (*Player) Resume

func (p *Player) Resume()

Resume will resume a paused stream

func (*Player) SendNotice

func (p *Player) SendNotice(title, body, footer string)

func (*Player) SetVolume

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

SetVolume will set the volume for the next track

func (*Player) SetVolumePercent

func (p *Player) SetVolumePercent(v int) error

func (*Player) Skip

func (p *Player) Skip()

Skip will skip the currently playing track

func (*Player) Stop

func (p *Player) Stop()

Stop will immediately stop the player

func (*Player) Stopped

func (p *Player) Stopped() bool

func (*Player) UpdateConf

func (p *Player) UpdateConf(gc *models.Conf)

func (*Player) Volume

func (p *Player) Volume() int

type Players

type Players struct {
	sync.RWMutex
	Players map[string]*Player
}

Players will hold the guild players

func NewPlayers

func NewPlayers() *Players

NewPlayers instantiates the player map

func (*Players) Create

func (p *Players) Create(s *discordgo.Session, conf *cmd.Conf, log zerolog.Logger, guild string, storage *storage.StormDB, gc *models.Conf) error

Create will create a new player and associate it with the guild

func (*Players) GetPlayer

func (p *Players) GetPlayer(guildID string) *Player

GetPlayer will get the player associated with the guild ID if any

func (*Players) Kill

func (p *Players) Kill()

Kill will kill all the players

type Queue

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

func NewQueue

func NewQueue(s *State) *Queue

func (*Queue) Append

func (q *Queue) Append(t ...tracks.Track)

Append will append tracks at the end of queue.

func (*Queue) Clear

func (q *Queue) Clear()

Clear will reset the queue, removing all tracks from it except the first one if it is currently played.

func (*Queue) Duration

func (q *Queue) Duration() int

Duration will return the total duration of the active queue.

func (*Queue) DurationString

func (q *Queue) DurationString() string

DurationString will return the total duration of the active queue in human readable format.

func (*Queue) GenerateQueueEmbed

func (q *Queue) GenerateQueueEmbed() *discordgo.MessageEmbed

func (*Queue) Get

func (q *Queue) Get() tracks.Track

Get will return the first track in queue if any. If there is no track in queue, nil will be returned.

func (*Queue) Len

func (q *Queue) Len() int

Len will return the current number of tracks in queue.

func (*Queue) Loop

func (q *Queue) Loop()

Loop will move the first track at the end of the queue if there is more than one track in queue. Otherwise it does nothing, leaving the first track in its position to be played once more.

func (*Queue) Pop

func (q *Queue) Pop()

Pop will remove the first track in queue.

func (*Queue) Prepend

func (q *Queue) Prepend(t ...tracks.Track)

Prepend will add tracks to the start of the queue, either right after the currently playing track, or right at the start if the player is stopped.

func (*Queue) RemoveN

func (q *Queue) RemoveN(n int)

RemoveN will remove the next n tracks in queue

func (*Queue) Shuffle

func (q *Queue) Shuffle()

Shuffle will shuffle all the tracks in queue, except the first one if it's currently being played.

type State

type State struct {
	sync.RWMutex
	Playing bool
	Stopped bool
	Paused  bool
	Volume  int
}

State stores the various state of the player. It is also used by the queue to determine some actions related to currently playing tracks.

func NewState

func NewState() *State

NewPlayerState will return a new player state

type Stats

type Stats struct {
	sync.RWMutex

	PlaybackPosition time.Duration
	Duration         time.Duration
	Bitrate          float32
	Size             int
	Speed            float32
	TimeAxis         []float64
	BiteRateAxis     []float64
}

func (*Stats) GenerateChart

func (s *Stats) GenerateChart() *chart.Chart

Jump to

Keyboard shortcuts

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