audio

package
v0.0.0-...-2824937 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT, BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package audio provides a basic audio player.

In order to use this package on Linux desktop distros, you will need OpenAL library as an external dependency. On Ubuntu 14.04 'Trusty', you may have to install this library by running the command below.

sudo apt-get install libopenal-dev

When compiled for Android, this package uses OpenAL Soft as a backend. Please add its license file to the open source notices of your application. OpenAL Soft's license file could be found at http://repo.or.cz/w/openal-soft.git/blob/HEAD:/COPYING.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format int

Format represents a PCM data format.

const (
	Mono8 Format = iota + 1
	Mono16
	Stereo8
	Stereo16
)

func (Format) String

func (f Format) String() string

type Player

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

Player is a basic audio player that plays PCM data. Operations on a nil *Player are no-op, a nil *Player can be used for testing purposes.

func NewPlayer

func NewPlayer(src ReadSeekCloser, format Format, samplesPerSecond int64) (*Player, error)

NewPlayer returns a new Player. It initializes the underlying audio devices and the related resources. If zero values are provided for format and sample rate values, the player determines them from the source's WAV header. An error is returned if the format and sample rate can't be determined.

The audio package is only designed for small audio sources.

func (*Player) Close

func (p *Player) Close() error

Close closes the device and frees the underlying resources used by the player. It should be called as soon as the player is not in-use anymore.

func (*Player) Current

func (p *Player) Current() time.Duration

Current returns the current playback position of the audio that is being played.

func (*Player) Pause

func (p *Player) Pause() error

Pause pauses the player.

func (*Player) Play

func (p *Player) Play() error

Play buffers the source audio to the audio device and starts to play the source. If the player paused or stopped, it reuses the previously buffered resources to keep playing from the time it has paused or stopped.

func (*Player) Seek

func (p *Player) Seek(offset time.Duration) error

Seek moves the play head to the given offset relative to the start of the source.

func (*Player) SetVolume

func (p *Player) SetVolume(vol float64)

SetVolume sets the volume of the player. The range of the volume is [0, 1].

func (*Player) State

func (p *Player) State() State

State returns the player's current state.

func (*Player) Stop

func (p *Player) Stop() error

Stop stops the player.

func (*Player) Total

func (p *Player) Total() time.Duration

Total returns the total duration of the audio source.

func (*Player) Volume

func (p *Player) Volume() float64

Volume returns the current player volume. The range of the volume is [0, 1].

type ReadSeekCloser

type ReadSeekCloser interface {
	io.ReadSeeker
	io.Closer
}

ReadSeekCloser is an io.ReadSeeker and io.Closer.

type State

type State int

State indicates the current playing state of the player.

const (
	Unknown State = iota
	Initial
	Playing
	Paused
	Stopped
)

func (State) String

func (s State) String() string

Directories

Path Synopsis
Package al provides OpenAL Soft bindings for Go.
Package al provides OpenAL Soft bindings for Go.

Jump to

Keyboard shortcuts

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