Documentation ¶
Overview ¶
Package speaker implements playback of beep.Streamer values through physical speakers.
Index ¶
- func Init(sampleRate beep.SampleRate) error
- func Play(s ...beep.Streamer)
- func Resume() error
- func Suspend() error
- type Player
- func (s *Player) Close() error
- func (s *Player) DurationPlayed() time.Duration
- func (s *Player) Err() error
- func (s *Player) IsPlaying() bool
- func (s *Player) Pause()
- func (s *Player) Play()
- func (s *Player) Reset()
- func (s *Player) SamplesPlayed() int
- func (s *Player) SetVolume(v float64)
- func (s *Player) UnplayedBufferSize() int
- func (s *Player) Volume() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(sampleRate beep.SampleRate) error
Init initializes audio playback through speaker. Must be called before using this package.
func Play ¶
Play starts playing all provided Streamers through the speaker. Each player will be closed automatically after the streamer ends.
Play is a convenience function for (some) backwards compatibility. To have more control, use NewPlayer() instead.
Types ¶
type Player ¶ added in v1.0.3
type Player struct {
// contains filtered or unexported fields
}
Player gives control over the playback of the Steamer.
func NewPlayer ¶ added in v1.0.3
NewPlayer creates a Player from a Streamer. Player can be used to finely control playback of the stream. A player has an internal buffer that will be filled by pulling samples from Streamer and will be drained by the audio being played. So their position won't necessarily match exactly. If you want to clear the underlying buffer for some reasons e.g., you want to seek the position of s, call the player's Reset() function. NewPlayer is concurrent safe, however s cannot be used by multiple players.
func (*Player) Close ¶ added in v1.0.3
Close the player and remove it from the speaker. Streamer is *not* closed.
func (*Player) DurationPlayed ¶ added in v1.0.3
DurationPlayed returns the playtime of this player based on the samples played and the sample rate speaker was initialized with. If the player is in a paused state, this will not increase.
func (*Player) Play ¶ added in v1.0.3
func (s *Player) Play()
Play resumes playing after playback was paused.
func (*Player) Reset ¶ added in v1.0.3
func (s *Player) Reset()
Reset clears the underlying buffer and pauses its playing. This can be useful when you want to Seek() or make other modifications to the Streamer. In this case, call Reset() before seeking or other functions. Reset will also reset SamplesPlayed and DurationPlayed.
func (*Player) SamplesPlayed ¶ added in v1.0.3
SamplesPlayed returns the total number of samples played through this player. If the player is in a paused state, this will not increase.
func (*Player) SetVolume ¶ added in v1.0.3
SetVolume sets the current volume in the range of [0, 1].
func (*Player) UnplayedBufferSize ¶ added in v1.0.3
UnplayedBufferSize returns the byte size in the underlying buffer that is not played yet.