audioplayer

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package audioplayer plays audio from a URL or from bytes, with pause, seek, volume, speed and looping. It needs no permission. For a spoken turn with the microphone, see the audio plugin.

nimbus native plugin add audio-player

p, err := audioplayer.Open(ctx, audioplayer.Source{URL: "https://example.com/show.mp3"})
defer p.Close(ctx)
p.Play(ctx)
go p.Watch(ctx, setStatus)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Player

type Player struct {
	// contains filtered or unexported fields
}

Player is one sound. Close it when you're done.

func Open

func Open(ctx context.Context, s Source) (*Player, error)

Open loads it, ready to play, and returns once it's ready.

func (*Player) Close

func (p *Player) Close(ctx context.Context) error

Close stops it and lets go of it.

func (*Player) Pause

func (p *Player) Pause(ctx context.Context) error

Pause stops it where it is.

func (*Player) Play

func (p *Player) Play(ctx context.Context) error

Play starts it, or carries on after Pause. After the end, it starts again.

func (*Player) Seek

func (p *Player) Seek(ctx context.Context, seconds float64) error

Seek jumps to a place.

func (*Player) SetLoop

func (p *Player) SetLoop(ctx context.Context, loop bool) error

SetLoop makes it start again at the end.

func (*Player) SetRate

func (p *Player) SetRate(ctx context.Context, rate float64) error

SetRate sets its speed, keeping the pitch.

func (*Player) SetVolume

func (p *Player) SetVolume(ctx context.Context, volume float64) error

SetVolume sets how loud it is, within the phone's own volume.

func (*Player) Status

func (p *Player) Status(ctx context.Context) (Status, error)

Status says where it's got to.

func (*Player) Watch

func (p *Player) Watch(ctx context.Context, f func(Status)) error

Watch calls f about four times a second until ctx ends. It blocks, so run it from a goroutine in an effect.

type Source

type Source struct {
	URL  string `json:"url,omitempty"`  // an https address
	Data []byte `json:"data,omitempty"` // or the file itself
	Type string `json:"type,omitempty"` // Data's MIME type, such as "audio/mp4"
}

Source is what to play: a URL, or Data with its Type.

type Status

type Status struct {
	Position float64 `json:"position"` // seconds in
	Duration float64 `json:"duration"` // seconds long; 0 for a live stream
	Playing  bool    `json:"playing"`  // it's playing now
	Ended    bool    `json:"ended"`    // it reached the end
}

Status is where it's got to.

Jump to

Keyboard shortcuts

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