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)
| 42 | // which will play the audio encoded in the specified file. |
| 43 | // Currently it supports wave and Ogg Vorbis formats. |
| 44 | func 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 |
| 72 | func (p *Player) Dispose() { |
nothing calls this directly
no test coverage detected