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()
})
runLoop = true
}
// Fill the first part before playing to reduce noises (#1632).
buf := make([]byte, p.context.oneBufferSize())
buf := make([]byte, p.context.maxBufferSize())
for p.p.UnplayedBufferSize() < int64(p.context.maxBufferSize()) {
n, err := p.src.Read(buf)
if err != nil && err != io.EOF {
p.setErrorImpl(err)
return
}
p.p.AppendBuffer(buf[:n])
if err == io.EOF {
break
}
}
if err := p.p.Play(); err != nil {
p.setErrorImpl(err)
return