audio: bug fix: test out of memory on browsers

This commit is contained in:
Hajime Hoshi 2024-07-13 23:08:25 +09:00
parent 6f74e03cb3
commit bf3ded2a55

View File

@ -17,6 +17,7 @@ package audio
import (
"io"
"sync"
"time"
)
type (
@ -63,8 +64,16 @@ func (p *dummyPlayer) Play() {
p.playing = true
p.m.Unlock()
go func() {
if _, err := io.ReadAll(p.r); err != nil {
panic(err)
var buf [4096]byte
for {
_, err := p.r.Read(buf[:])
if err != nil {
if err != io.EOF {
panic(err)
}
break
}
time.Sleep(time.Millisecond)
}
p.m.Lock()
p.playing = false