mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
audio/internal/readerdriver: Add Player.Err
This commit is contained in:
parent
b46cb324ed
commit
f4b770eff6
@ -149,7 +149,9 @@ func NewContext(sampleRate int) *Context {
|
||||
return err
|
||||
}
|
||||
|
||||
c.gcPlayers()
|
||||
if err := c.gcPlayers(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -206,7 +208,7 @@ func (c *Context) removePlayer(p playerImpl) {
|
||||
c.m.Unlock()
|
||||
}
|
||||
|
||||
func (c *Context) gcPlayers() {
|
||||
func (c *Context) gcPlayers() error {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
@ -217,12 +219,17 @@ func (c *Context) gcPlayers() {
|
||||
for p := range c.players {
|
||||
rp, ok := p.(*readerPlayer)
|
||||
if !ok {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
if err := rp.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !rp.IsPlaying() {
|
||||
delete(c.players, p)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsReady returns a boolean value indicating whether the audio is ready or not.
|
||||
|
@ -200,6 +200,10 @@ func (p *Player) UnplayedBufferSize() int64 {
|
||||
return int64(p.v.Get("unplayedBufferSize").Int())
|
||||
}
|
||||
|
||||
func (p *Player) Err() error {
|
||||
return p.err
|
||||
}
|
||||
|
||||
func (p *Player) Close() error {
|
||||
runtime.SetFinalizer(p, nil)
|
||||
return p.close(true)
|
||||
|
@ -32,5 +32,6 @@ type Player interface {
|
||||
Volume() float64
|
||||
SetVolume(volume float64)
|
||||
UnplayedBufferSize() int64
|
||||
Err() error
|
||||
io.Closer
|
||||
}
|
||||
|
@ -259,12 +259,16 @@ func (p *playerImpl) UnplayedBufferSize() int64 {
|
||||
return int64(sec * float64(p.context.sampleRate*p.context.channelNum*p.context.bitDepthInBytes))
|
||||
}
|
||||
|
||||
func (p *playerImpl) Err() error {
|
||||
return p.err
|
||||
}
|
||||
|
||||
func (p *playerImpl) Close() error {
|
||||
runtime.SetFinalizer(p, nil)
|
||||
p.Reset()
|
||||
p.state = readerPlayerClosed
|
||||
p.appendBufferFunc.Release()
|
||||
return p.err
|
||||
return nil
|
||||
}
|
||||
|
||||
type go2cppDriverWrapper struct {
|
||||
|
@ -199,6 +199,16 @@ func (p *readerPlayer) Seek(offset time.Duration) error {
|
||||
return p.stream.Seek(offset)
|
||||
}
|
||||
|
||||
func (p *readerPlayer) Err() error {
|
||||
p.m.Lock()
|
||||
defer p.m.Unlock()
|
||||
|
||||
if p.player == nil {
|
||||
return nil
|
||||
}
|
||||
return p.player.Err()
|
||||
}
|
||||
|
||||
func (p *readerPlayer) source() io.Reader {
|
||||
return p.src
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user