audio/internal/readerdriver: Fill the buffer whenever starting to play

This commit is contained in:
Hajime Hoshi 2021-05-09 03:51:45 +09:00
parent ae9e89b814
commit fcdd4e16d4

View File

@ -110,16 +110,21 @@ func (p *player) Play() {
p.cond.Signal() p.cond.Signal()
}) })
runLoop = true runLoop = true
}
// Fill the first part before playing to reduce noises (#1632). buf := make([]byte, p.context.maxBufferSize())
buf := make([]byte, p.context.oneBufferSize()) for p.p.UnplayedBufferSize() < int64(p.context.maxBufferSize()) {
n, err := p.src.Read(buf) n, err := p.src.Read(buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
p.setErrorImpl(err) p.setErrorImpl(err)
return return
} }
p.p.AppendBuffer(buf[:n]) p.p.AppendBuffer(buf[:n])
if err == io.EOF {
break
}
} }
if err := p.p.Play(); err != nil { if err := p.p.Play(); err != nil {
p.setErrorImpl(err) p.setErrorImpl(err)
return return