MCPcopy
hub / github.com/g3n/engine / NewPlayer

Function NewPlayer

audio/player.go:44–69  ·  view source on GitHub ↗

NewPlayer creates and returns a pointer to a new audio player object which will play the audio encoded in the specified file. Currently it supports wave and Ogg Vorbis formats.

(filename string)

Source from the content-addressed store, hash-verified

42// which will play the audio encoded in the specified file.
43// Currently it supports wave and Ogg Vorbis formats.
44func NewPlayer(filename string) (*Player, error) {
45
46 // Try to open audio file
47 af, err := NewAudioFile(filename)
48 if err != nil {
49 return nil, err
50 }
51
52 // Creates player
53 p := new(Player)
54 p.Node.Init(p)
55 p.af = af
56
57 // Generate buffers names
58 p.buffers = al.GenBuffers(playerBufferCount)
59
60 // Generate source name
61 p.source = al.GenSource()
62
63 // Allocates C memory buffer
64 p.pdata = C.malloc(playerBufferSize)
65
66 // Initialize channel for communication with internal goroutine
67 p.gchan = make(chan string, 1)
68 return p, nil
69}
70
71// Dispose disposes of this player resources
72func (p *Player) Dispose() {

Callers

nothing calls this directly

Calls 4

GenBuffersFunction · 0.92
GenSourceFunction · 0.92
NewAudioFileFunction · 0.85
InitMethod · 0.45

Tested by

no test coverage detected