mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Treat Oto context's error
This commit is contained in:
parent
5cebe867d4
commit
d9967c53e5
@ -126,9 +126,7 @@ func NewContext(sampleRate int) *Context {
|
|||||||
var err error
|
var err error
|
||||||
theContextLock.Lock()
|
theContextLock.Lock()
|
||||||
if theContext != nil {
|
if theContext != nil {
|
||||||
theContext.m.Lock()
|
err = theContext.error()
|
||||||
err = theContext.err
|
|
||||||
theContext.m.Unlock()
|
|
||||||
}
|
}
|
||||||
theContextLock.Unlock()
|
theContextLock.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,13 +150,6 @@ func CurrentContext() *Context {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) hasError() bool {
|
|
||||||
c.m.Lock()
|
|
||||||
r := c.err != nil
|
|
||||||
c.m.Unlock()
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) setError(err error) {
|
func (c *Context) setError(err error) {
|
||||||
// TODO: What if c.err already exists?
|
// TODO: What if c.err already exists?
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
@ -166,6 +157,15 @@ func (c *Context) setError(err error) {
|
|||||||
c.m.Unlock()
|
c.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) error() error {
|
||||||
|
c.m.Lock()
|
||||||
|
defer c.m.Unlock()
|
||||||
|
if c.err != nil {
|
||||||
|
return c.err
|
||||||
|
}
|
||||||
|
return c.playerFactory.error()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) setReady() {
|
func (c *Context) setReady() {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
c.ready = true
|
c.ready = true
|
||||||
|
@ -67,6 +67,10 @@ func (c *Context) Resume() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) Err() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) oneBufferSize() int {
|
func (c *Context) oneBufferSize() int {
|
||||||
// TODO: This must be audio.oneBufferSize(p.context.sampleRate). Avoid the duplication.
|
// TODO: This must be audio.oneBufferSize(p.context.sampleRate). Avoid the duplication.
|
||||||
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4
|
return c.sampleRate * c.channelNum * c.bitDepthInBytes / 4
|
||||||
|
@ -27,6 +27,7 @@ type context interface {
|
|||||||
NewPlayer(io.Reader) oto.Player
|
NewPlayer(io.Reader) oto.Player
|
||||||
Suspend() error
|
Suspend() error
|
||||||
Resume() error
|
Resume() error
|
||||||
|
Err() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type playerFactory struct {
|
type playerFactory struct {
|
||||||
@ -91,6 +92,16 @@ func (f *playerFactory) resume() error {
|
|||||||
return f.context.Resume()
|
return f.context.Resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *playerFactory) error() error {
|
||||||
|
f.m.Lock()
|
||||||
|
defer f.m.Unlock()
|
||||||
|
|
||||||
|
if f.context == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return f.context.Err()
|
||||||
|
}
|
||||||
|
|
||||||
func (f *playerFactory) initContextIfNeeded() (<-chan struct{}, error) {
|
func (f *playerFactory) initContextIfNeeded() (<-chan struct{}, error) {
|
||||||
f.m.Lock()
|
f.m.Lock()
|
||||||
defer f.m.Unlock()
|
defer f.m.Unlock()
|
||||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/hajimehoshi/bitmapfont/v2 v2.1.3
|
github.com/hajimehoshi/bitmapfont/v2 v2.1.3
|
||||||
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41
|
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41
|
||||||
github.com/hajimehoshi/go-mp3 v0.3.2
|
github.com/hajimehoshi/go-mp3 v0.3.2
|
||||||
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2
|
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2.0.20211022061803-81e245b09d0b
|
||||||
github.com/jakecoffman/cp v1.1.0
|
github.com/jakecoffman/cp v1.1.0
|
||||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240
|
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240
|
||||||
github.com/jfreymuth/oggvorbis v1.0.3
|
github.com/jfreymuth/oggvorbis v1.0.3
|
||||||
|
4
go.sum
4
go.sum
@ -9,8 +9,8 @@ github.com/hajimehoshi/go-mp3 v0.3.2 h1:xSYNE2F3lxtOu9BRjCWHHceg7S91IHfXfXp5+LYQ
|
|||||||
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
|
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
|
||||||
github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
|
github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
|
||||||
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
|
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
|
||||||
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2 h1:DV2DcbY3YLuLB9gI9R1GT9TPOo92lUeWveV8ci1sBLk=
|
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2.0.20211022061803-81e245b09d0b h1:DyHaCwXYwsZMLawB9G7uDP18WHvwO8KXm9JROxTY5ew=
|
||||||
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
|
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2.0.20211022061803-81e245b09d0b/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
|
||||||
github.com/jakecoffman/cp v1.1.0 h1:bhKvCNbAddYegYHSV5abG3G23vZdsISgqXa4X/lK8Oo=
|
github.com/jakecoffman/cp v1.1.0 h1:bhKvCNbAddYegYHSV5abG3G23vZdsISgqXa4X/lK8Oo=
|
||||||
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
|
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
|
||||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
|
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
|
||||||
|
Loading…
Reference in New Issue
Block a user