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