audio: Replace 'for' with 'if' as preparation to avoid goroutine

This commit is contained in:
Hajime Hoshi 2016-04-05 03:31:37 +09:00
parent ff8f15a212
commit 2d3c3e361e
2 changed files with 2 additions and 2 deletions

View File

@ -100,7 +100,7 @@ func (p *player) proceed() error {
p.alBuffers = append(p.alBuffers, bufs...) p.alBuffers = append(p.alBuffers, bufs...)
} }
for 0 < len(p.alBuffers) { if 0 < len(p.alBuffers) {
n, err := p.source.Read(tmpBuffer) n, err := p.source.Read(tmpBuffer)
if 0 < n { if 0 < n {
buf := p.alBuffers[0] buf := p.alBuffers[0]
@ -130,7 +130,6 @@ func (p *player) proceed() error {
return nil return nil
} }
// TODO: When is this called? Can we remove this?
func (p *player) close() error { func (p *player) close() error {
if err := al.Error(); err != 0 { if err := al.Error(); err != 0 {
return fmt.Errorf("audio: error before closing: %d", err) return fmt.Errorf("audio: error before closing: %d", err)

View File

@ -116,6 +116,7 @@ func newPlayer(src io.Reader, sampleRate int) (*player, error) {
} }
func (p *player) proceed() error { func (p *player) proceed() error {
// TODO: Read should be called only when there are buffers available?
b := make([]byte, bufferSize) b := make([]byte, bufferSize)
n, err := p.src.Read(b) n, err := p.src.Read(b)
if 0 < n { if 0 < n {