audio: Bug fix: Need to call setReady from the reader player side

Updates #1599
This commit is contained in:
Hajime Hoshi 2021-04-19 23:55:26 +09:00
parent b1545b115c
commit ea9d64f5b8
3 changed files with 6 additions and 3 deletions

View File

@ -25,6 +25,6 @@ func IsAvailable() bool {
return false return false
} }
func NewContext(sampleRate int, channelNum int, bitDepthInBytes int) (Context, error) { func NewContext(sampleRate int, channelNum int, bitDepthInBytes int, onReady func()) (Context, error) {
panic(fmt.Sprintf("readerdriver: NewContext is not available on this environment: GOOS=%s", runtime.GOOS)) panic(fmt.Sprintf("readerdriver: NewContext is not available on this environment: GOOS=%s", runtime.GOOS))
} }

View File

@ -40,7 +40,7 @@ type contextImpl struct {
bitDepthInBytes int bitDepthInBytes int
} }
func NewContext(sampleRate int, channelNum int, bitDepthInBytes int) (Context, error) { func NewContext(sampleRate int, channelNum int, bitDepthInBytes int, onReady func()) (Context, error) {
if js.Global().Get("go2cpp").Truthy() { if js.Global().Get("go2cpp").Truthy() {
return &go2cppDriverWrapper{go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes)}, nil return &go2cppDriverWrapper{go2cpp.NewContext(sampleRate, channelNum, bitDepthInBytes)}, nil
} }
@ -68,6 +68,7 @@ func NewContext(sampleRate int, channelNum int, bitDepthInBytes int) (Context, e
if !d.ready { if !d.ready {
d.audioContext.Call("resume") d.audioContext.Call("resume")
d.ready = true d.ready = true
onReady()
} }
js.Global().Get("document").Call("removeEventListener", event, f) js.Global().Get("document").Call("removeEventListener", event, f)
return nil return nil

View File

@ -68,7 +68,9 @@ func (p *readerPlayer) ensurePlayer() error {
// is unexpectable. // is unexpectable.
// e.g. a variable for JVM on Android might not be set. // e.g. a variable for JVM on Android might not be set.
if p.factory.context == nil { if p.factory.context == nil {
c, err := readerdriver.NewContext(p.factory.sampleRate, channelNum, bitDepthInBytes) c, err := readerdriver.NewContext(p.factory.sampleRate, channelNum, bitDepthInBytes, func() {
p.context.setReady()
})
if err != nil { if err != nil {
return err return err
} }