audio/internal/readerdriver: Enable to return error at Suspend/Resume

This commit is contained in:
Hajime Hoshi 2021-05-04 23:18:16 +09:00
parent 58843b68f9
commit 804881fa94
5 changed files with 24 additions and 18 deletions

View File

@ -127,15 +127,15 @@ func NewContext(sampleRate int) *Context {
h := getHook() h := getHook()
h.OnSuspendAudio(func() error { h.OnSuspendAudio(func() error {
c.semaphore <- struct{}{} c.semaphore <- struct{}{}
if s, ok := np.(interface{ suspend() }); ok { if s, ok := np.(interface{ suspend() error }); ok {
s.suspend() return s.suspend()
} }
return nil return nil
}) })
h.OnResumeAudio(func() error { h.OnResumeAudio(func() error {
<-c.semaphore <-c.semaphore
if s, ok := np.(interface{ resume() }); ok { if s, ok := np.(interface{ resume() error }); ok {
s.resume() return s.resume()
} }
return nil return nil
}) })

View File

@ -68,10 +68,12 @@ func (c *dummyReaderContext) MaxBufferSize() int {
return 48000 * channelNum * bitDepthInBytes / 4 return 48000 * channelNum * bitDepthInBytes / 4
} }
func (c *dummyReaderContext) Suspend() { func (c *dummyReaderContext) Suspend() error {
return nil
} }
func (c *dummyReaderContext) Resume() { func (c *dummyReaderContext) Resume() error {
return nil
} }
func (c *dummyReaderContext) Close() error { func (c *dummyReaderContext) Close() error {

View File

@ -21,8 +21,8 @@ import (
type Context interface { type Context interface {
NewPlayer(io.Reader) Player NewPlayer(io.Reader) Player
MaxBufferSize() int MaxBufferSize() int
Suspend() Suspend() error
Resume() Resume() error
io.Closer io.Closer
} }

View File

@ -139,12 +139,14 @@ func (c *context) MaxBufferSize() int {
return c.oneBufferSize() * 2 return c.oneBufferSize() * 2
} }
func (c *context) Suspend() { func (c *context) Suspend() error {
c.audioContext.Call("suspend") c.audioContext.Call("suspend")
return nil
} }
func (c *context) Resume() { func (c *context) Resume() error {
c.audioContext.Call("resume") c.audioContext.Call("resume")
return nil
} }
func (p *player) Pause() { func (p *player) Pause() {
@ -307,12 +309,14 @@ func (w *go2cppDriverWrapper) MaxBufferSize() int {
return w.c.MaxBufferSize() return w.c.MaxBufferSize()
} }
func (w *go2cppDriverWrapper) Suspend() { func (w *go2cppDriverWrapper) Suspend() error {
// Do nothing so far. // Do nothing so far.
return nil
} }
func (w *go2cppDriverWrapper) Resume() { func (w *go2cppDriverWrapper) Resume() error {
// Do nothing so far. // Do nothing so far.
return nil
} }
func (w *go2cppDriverWrapper) Close() error { func (w *go2cppDriverWrapper) Close() error {

View File

@ -60,18 +60,18 @@ func (f *readerPlayerFactory) newPlayerImpl(context *Context, src io.Reader) (pl
return p, nil return p, nil
} }
func (f *readerPlayerFactory) suspend() { func (f *readerPlayerFactory) suspend() error {
if f.context == nil { if f.context == nil {
return return nil
} }
f.context.Suspend() return f.context.Suspend()
} }
func (f *readerPlayerFactory) resume() { func (f *readerPlayerFactory) resume() error {
if f.context == nil { if f.context == nil {
return return nil
} }
f.context.Resume() return f.context.Resume()
} }
func (p *readerPlayer) ensurePlayer() error { func (p *readerPlayer) ensurePlayer() error {