Documentation
¶
Overview ¶
Package playback provides an interface for audio playback, allowing audio to be sent to various drivers and devices.
Fun fact: the first audio played using this package was the song Parasol Cider by MORE MORE JUMP!.
Example ¶
package main
import (
"os"
"github.com/SladkyCitron/resona/codec"
_ "github.com/SladkyCitron/resona/codec/wav"
"github.com/SladkyCitron/resona/playback"
_ "github.com/SladkyCitron/resona/playback/driver/oto"
)
func main() {
// Open the audio file
f, err := os.Open("file.wav")
if err != nil {
panic(err)
}
defer f.Close()
// Decode audio file into an aio.SampleReader
decoder, _, err := codec.Decode(f)
if err != nil {
panic(err)
}
// Create audio playback context with Oto as the driver
ctx, err := playback.NewContext(decoder.Format(), playback.WithDriver("oto"))
if err != nil {
panic(err)
}
defer ctx.Close()
// Create player and start playback
player := ctx.NewPlayer(decoder)
player.PlayAndWait() // Play and block until done
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the playback context.
func NewContext ¶
func NewContext(format afmt.Format, opts ...ContextOption) (*Context, error)
NewContext creates a new Context with the specified format and options. If no driver is specified, the default driver (first one registered) is used.
type ContextOption ¶
type ContextOption func(*Context)
ContextOption represents an option for configuring Context.
func WithBufferSize ¶
func WithBufferSize(size int) ContextOption
WithBufferSize sets the buffer size. Bigger buffer size means lower CPU usage and more reliable playback. Lower buffer size means better responsiveness and less delay.
func WithBufferSizeBytes ¶
func WithBufferSizeBytes(size int) ContextOption
WithBufferSizeBytes sets the buffer size in bytes. Bigger buffer size means lower CPU usage and more reliable playback. Lower buffer size means better responsiveness and less delay.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player represents an audio player.
func (*Player) PlayAndWait ¶
func (p *Player) PlayAndWait()
PlayAndWait starts the playback and blocks until the player has finished playing and drained.
func (*Player) PlayWithDone ¶
func (p *Player) PlayWithDone() chan struct{}
PlayWithDone starts the playback and returns a channel that closes when the player has finished playing and drained.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package driver provides the interface for playback drivers.
|
Package driver provides the interface for playback drivers. |
|
ffplay
Package ffplay provides a FFplay-based playback driver.
|
Package ffplay provides a FFplay-based playback driver. |
|
oto
Package oto provides a cross-platform [Oto]-based playback driver.
|
Package oto provides a cross-platform [Oto]-based playback driver. |