mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio/internal/readerdriver: Enable to return error at Suspend/Resume
This commit is contained in:
parent
58843b68f9
commit
804881fa94
@ -127,15 +127,15 @@ func NewContext(sampleRate int) *Context {
|
||||
h := getHook()
|
||||
h.OnSuspendAudio(func() error {
|
||||
c.semaphore <- struct{}{}
|
||||
if s, ok := np.(interface{ suspend() }); ok {
|
||||
s.suspend()
|
||||
if s, ok := np.(interface{ suspend() error }); ok {
|
||||
return s.suspend()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
h.OnResumeAudio(func() error {
|
||||
<-c.semaphore
|
||||
if s, ok := np.(interface{ resume() }); ok {
|
||||
s.resume()
|
||||
if s, ok := np.(interface{ resume() error }); ok {
|
||||
return s.resume()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@ -68,10 +68,12 @@ func (c *dummyReaderContext) MaxBufferSize() int {
|
||||
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 {
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
type Context interface {
|
||||
NewPlayer(io.Reader) Player
|
||||
MaxBufferSize() int
|
||||
Suspend()
|
||||
Resume()
|
||||
Suspend() error
|
||||
Resume() error
|
||||
io.Closer
|
||||
}
|
||||
|
||||
|
@ -139,12 +139,14 @@ func (c *context) MaxBufferSize() int {
|
||||
return c.oneBufferSize() * 2
|
||||
}
|
||||
|
||||
func (c *context) Suspend() {
|
||||
func (c *context) Suspend() error {
|
||||
c.audioContext.Call("suspend")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) Resume() {
|
||||
func (c *context) Resume() error {
|
||||
c.audioContext.Call("resume")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *player) Pause() {
|
||||
@ -307,12 +309,14 @@ func (w *go2cppDriverWrapper) MaxBufferSize() int {
|
||||
return w.c.MaxBufferSize()
|
||||
}
|
||||
|
||||
func (w *go2cppDriverWrapper) Suspend() {
|
||||
func (w *go2cppDriverWrapper) Suspend() error {
|
||||
// Do nothing so far.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *go2cppDriverWrapper) Resume() {
|
||||
func (w *go2cppDriverWrapper) Resume() error {
|
||||
// Do nothing so far.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *go2cppDriverWrapper) Close() error {
|
||||
|
@ -60,18 +60,18 @@ func (f *readerPlayerFactory) newPlayerImpl(context *Context, src io.Reader) (pl
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (f *readerPlayerFactory) suspend() {
|
||||
func (f *readerPlayerFactory) suspend() error {
|
||||
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 {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
f.context.Resume()
|
||||
return f.context.Resume()
|
||||
}
|
||||
|
||||
func (p *readerPlayer) ensurePlayer() error {
|
||||
|
Loading…
Reference in New Issue
Block a user