player

package
v0.0.0-...-ea66291 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package player provides audio playback management.

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueEmpty = errors.New("queue is empty")

Functions

This section is empty.

Types

type IPlayer

type IPlayer interface {
	Play(startAt int, song *Song)
	Skip()
	Enqueue(song *Song)
	Dequeue() (*Song, error)
	ClearQueue()
	Stop()
	Pause()
	Unpause()
	GetCurrentStatus() PlaybackStatus
	SetCurrentStatus(status PlaybackStatus)
	GetSongQueue() []*Song
	GetVoiceConnection() *discordgo.VoiceConnection
	SetVoiceConnection(voiceConnection *discordgo.VoiceConnection)
	GetStreamingSession() *dca.StreamingSession
	GetCurrentSong() *Song
}

IPlayer defines the interface for managing audio playback and song queue.

func NewPlayer

func NewPlayer(guildID string) IPlayer

NewPlayer creates a new Player instance.

type PlaybackStatus

type PlaybackStatus int32

PlaybackStatus represents the playback status of the Player.

const (
	StatusResting PlaybackStatus = iota
	StatusPlaying
	StatusPaused
	StatusError
)

func (PlaybackStatus) String

func (status PlaybackStatus) String() string

String returns the string representation of the PlaybackStatus.

func (PlaybackStatus) StringEmoji

func (status PlaybackStatus) StringEmoji() string

type Player

type Player struct {
	sync.Mutex
	VoiceConnection  *discordgo.VoiceConnection
	StreamingSession *dca.StreamingSession
	EncodingSession  *dca.EncodeSession
	SongQueue        []*Song
	CurrentSong      *Song
	CurrentStatus    PlaybackStatus
	SkipInterrupt    chan bool
}

Player manages audio playback and song queue.

func (*Player) ClearQueue

func (p *Player) ClearQueue()

ClearQueue clears the song queue.

func (*Player) Dequeue

func (p *Player) Dequeue() (*Song, error)

Dequeue removes and returns the first song from the queue.

func (*Player) Enqueue

func (p *Player) Enqueue(song *Song)

Enqueue adds a song to the queue.

func (*Player) GetCurrentSong

func (p *Player) GetCurrentSong() *Song

GetCurrentSong returns the current song being played.

func (*Player) GetCurrentStatus

func (p *Player) GetCurrentStatus() PlaybackStatus

GetStatus returns the current playback status.

func (*Player) GetSongQueue

func (p *Player) GetSongQueue() []*Song

GetSongQueue returns the song queue.

func (*Player) GetStreamingSession

func (p *Player) GetStreamingSession() *dca.StreamingSession

GetStreamingSession returns the current streaming session.

func (*Player) GetVoiceConnection

func (p *Player) GetVoiceConnection() *discordgo.VoiceConnection

GetVoiceConnection returns the voice connection.

func (*Player) Pause

func (p *Player) Pause()

Pause pauses audio playback.

func (*Player) Play

func (p *Player) Play(startAt int, song *Song)

Play starts playing the current or specified song.

func (*Player) SetCurrentStatus

func (p *Player) SetCurrentStatus(status PlaybackStatus)

SetStatus sets the playback status.

func (*Player) SetVoiceConnection

func (p *Player) SetVoiceConnection(voiceConnection *discordgo.VoiceConnection)

SetVoiceConnection sets the voice connection.

func (*Player) Skip

func (p *Player) Skip()

Skip skips to the next song in the queue.

func (*Player) Stop

func (p *Player) Stop()

Stop stops audio playback and disconnects from the voice channel.

func (*Player) Unpause

func (p *Player) Unpause()

Unpause resumes audio playback.

type Song

type Song struct {
	Title       string        // Title of the song
	UserURL     string        // URL provided by the user
	DownloadURL string        // URL for downloading the song
	Thumbnail   Thumbnail     // Thumbnail image for the song
	Duration    time.Duration // Duration of the song
	ID          string        // Unique ID for the song
	Source      SongSource    // Source type of the song
}

Song represents a media item with relevant information.

type SongSource

type SongSource int32

SongSource represents the source type of the media.

const (
	SourceYouTube SongSource = iota
	SourceStream
)

func (SongSource) String

func (source SongSource) String() string

String returns the string representation of the SongSource.

type Thumbnail

type Thumbnail struct {
	URL    string
	Width  uint
	Height uint
}

Jump to

Keyboard shortcuts

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