Documentation
¶
Overview ¶
Package playback contains functions and types to stream and play audio
Index ¶
- Variables
- func CombineSamples(low []float64, high []float64) [][2]float64
- func Init(sampleRate int) error
- func QueueChunk(startTime int64, chunkID int64, samples [][2]float64)
- func SetVolume(v float64)
- type Playlist
- func (pl *Playlist) AddSong(song string)
- func (pl *Playlist) CurrentSong() string
- func (pl *Playlist) Fill(low []float64, high []float64) uint64
- func (pl *Playlist) InsertSong(song string, index int)
- func (pl *Playlist) Playing() bool
- func (pl *Playlist) Pos() int
- func (pl *Playlist) RemoveSong(index int) string
- func (pl *Playlist) SetNewSongHandler(nsh func(startSampleIndex uint64, filename string, songLength int64))
- func (pl *Playlist) SetPauseToggleHandler(psh func(playing bool, sample uint64))
- func (pl *Playlist) SetPlaying(p bool)
- func (pl *Playlist) SetPos(pos int)
- func (pl *Playlist) Songs() []string
- func (pl *Playlist) StreamLoop(ctx context.Context)
Constants ¶
This section is empty.
Variables ¶
var AudioDir string
AudioDir is the directory containing the audio file
Functions ¶
func CombineSamples ¶
CombineSamples combines to []float64 to one [][2]float64, such that low[i] == returned[i][0] and high[i] == returned[i][1]
func QueueChunk ¶
QueueChunk queue a chunk for playback
Types ¶
type Playlist ¶
type Playlist struct {
// contains filtered or unexported fields
}
Playlist is a array of songs, which can then be streamed. After reaching the end of the playlist, playback will resume at the start.
func NewPlaylist ¶
NewPlaylist create a new playlist with the given buffer size and songs in it, which inserts nanBreakSize nan-samples between songs, which players use to realign playback.
func (*Playlist) CurrentSong ¶
CurrentSong returns the song currently being played
func (*Playlist) Fill ¶
Fill reads the samples from the internal buffer and fills low and high with them. low and high must have the same length. returns the sampleIndex of the first read
func (*Playlist) InsertSong ¶
InsertSong inserts a song into the playlist. The index is clipped to the bounds of the playlist.
func (*Playlist) RemoveSong ¶
RemoveSong remove the song at index from the playlist and returns the removed song. The index is clipped to the bounds of the playlist. If the playlist is empty, noting happens and "" is returned.
func (*Playlist) SetNewSongHandler ¶
func (pl *Playlist) SetNewSongHandler(nsh func(startSampleIndex uint64, filename string, songLength int64))
SetNewSongHandler sets the new song handler, which is called every time the playlist begins playing a new song
func (*Playlist) SetPauseToggleHandler ¶
SetPauseToggleHandler sets the pause toggle handler, which is called every time the playlist is paused/resumed
func (*Playlist) SetPlaying ¶
SetPlaying can set whether or not the playlist should be playing audio.
func (*Playlist) StreamLoop ¶
StreamLoop reads the samples of the song into the internal buffer. This method blocks until the passed context is canceled. It must be called once before streaming from the playlist and must not be called again before the returning after the context was canceled.