mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 19:58:54 +01:00
audio/internal/readerdriver: Refactoring (js)
This commit is contained in:
parent
91d3d6b4e7
commit
8692ba5f06
@ -329,6 +329,12 @@ func (p *player) closeImpl() error {
|
|||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *player) setError(err error) {
|
||||||
|
p.cond.L.Lock()
|
||||||
|
defer p.cond.L.Unlock()
|
||||||
|
p.setErrorImpl(err)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *player) setErrorImpl(err error) {
|
func (p *player) setErrorImpl(err error) {
|
||||||
p.err = err
|
p.err = err
|
||||||
p.closeImpl()
|
p.closeImpl()
|
||||||
@ -366,16 +372,17 @@ func (p *player) loop() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.cond.L.Lock()
|
|
||||||
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.setError(err)
|
||||||
p.cond.L.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.cond.L.Lock()
|
||||||
p.buf = append(p.buf, buf[:n]...)
|
p.buf = append(p.buf, buf[:n]...)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
// p.eof can be true even if the buffer is not consumed yet.
|
||||||
|
// This might be different from the other drivers.
|
||||||
p.eof = true
|
p.eof = true
|
||||||
p.cond.L.Unlock()
|
p.cond.L.Unlock()
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user