Skip to content

Commit 5de9c71

Browse files
committed
oto: bug fix: oboe.Play can get stuck before the application is ready
Updates hajimehoshi/ebiten#3260
1 parent 73a7fea commit 5de9c71

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

driver_android.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ import (
2121

2222
type context struct {
2323
mux *mux.Mux
24+
25+
err atomicError
2426
}
2527

2628
func newContext(sampleRate int, channelCount int, format mux.Format, bufferSizeInBytes int, _ string) (*context, chan struct{}, error) {
2729
ready := make(chan struct{})
28-
close(ready)
2930

3031
c := &context{
3132
mux: mux.New(sampleRate, channelCount, format),
3233
}
33-
if err := oboe.Play(sampleRate, channelCount, c.mux.ReadFloat32s, bufferSizeInBytes); err != nil {
34-
return nil, nil, err
35-
}
34+
go func() {
35+
if err := oboe.Play(sampleRate, channelCount, c.mux.ReadFloat32s, bufferSizeInBytes); err != nil {
36+
c.err.TryStore(err)
37+
return
38+
}
39+
close(ready)
40+
}()
3641
return c, ready, nil
3742
}
3843

@@ -45,5 +50,5 @@ func (c *context) Resume() error {
4550
}
4651

4752
func (c *context) Err() error {
48-
return nil
53+
return c.err.Load()
4954
}

0 commit comments

Comments
 (0)