mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
audio: Remove (*mux).hasPlayer
This commit is contained in:
parent
96012b661f
commit
c4c6acacf9
@ -240,6 +240,7 @@ type playerImpl struct {
|
|||||||
src io.ReadCloser
|
src io.ReadCloser
|
||||||
srcEOF bool
|
srcEOF bool
|
||||||
sampleRate int
|
sampleRate int
|
||||||
|
playing bool
|
||||||
closedExplicitly bool
|
closedExplicitly bool
|
||||||
runningReadLoop bool
|
runningReadLoop bool
|
||||||
|
|
||||||
@ -351,22 +352,20 @@ func (p *Player) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) Close() error {
|
func (p *playerImpl) Close() error {
|
||||||
p.mux.removePlayer(p)
|
|
||||||
|
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
c := p.closedExplicitly
|
p.playing = false
|
||||||
p.m.Unlock()
|
p.mux.removePlayer(p)
|
||||||
if c {
|
if p.closedExplicitly {
|
||||||
|
p.m.Unlock()
|
||||||
return fmt.Errorf("audio: the player is already closed")
|
return fmt.Errorf("audio: the player is already closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.m.Lock()
|
|
||||||
p.closedExplicitly = true
|
p.closedExplicitly = true
|
||||||
p.m.Unlock()
|
|
||||||
// src.Close is called only when Player's Close is called.
|
// src.Close is called only when Player's Close is called.
|
||||||
if err := p.src.Close(); err != nil {
|
if err := p.src.Close(); err != nil {
|
||||||
|
p.m.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
p.m.Unlock()
|
||||||
return p.closeImpl()
|
return p.closeImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,6 +387,7 @@ func (p *playerImpl) ensureReadLoop() error {
|
|||||||
func (p *playerImpl) closeImpl() error {
|
func (p *playerImpl) closeImpl() error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
p.playing = false
|
||||||
if !p.runningReadLoop {
|
if !p.runningReadLoop {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -416,7 +416,10 @@ func (p *Player) Play() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) Play() {
|
func (p *playerImpl) Play() {
|
||||||
|
p.m.Lock()
|
||||||
|
p.playing = true
|
||||||
p.mux.addPlayer(p)
|
p.mux.addPlayer(p)
|
||||||
|
p.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) readLoop() {
|
func (p *playerImpl) readLoop() {
|
||||||
@ -584,7 +587,10 @@ func (p *Player) IsPlaying() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) IsPlaying() bool {
|
func (p *playerImpl) IsPlaying() bool {
|
||||||
return p.mux.hasPlayer(p)
|
p.m.Lock()
|
||||||
|
r := p.playing
|
||||||
|
p.m.Unlock()
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewind rewinds the current position to the start.
|
// Rewind rewinds the current position to the start.
|
||||||
@ -635,7 +641,10 @@ func (p *Player) Pause() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) Pause() {
|
func (p *playerImpl) Pause() {
|
||||||
|
p.m.Lock()
|
||||||
|
p.playing = false
|
||||||
p.mux.removePlayer(p)
|
p.mux.removePlayer(p)
|
||||||
|
p.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current returns the current position.
|
// Current returns the current position.
|
||||||
|
@ -143,10 +143,3 @@ func (m *mux) removePlayer(player *playerImpl) {
|
|||||||
delete(m.ps, player)
|
delete(m.ps, player)
|
||||||
m.m.Unlock()
|
m.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mux) hasPlayer(player *playerImpl) bool {
|
|
||||||
m.m.RLock()
|
|
||||||
_, ok := m.ps[player]
|
|
||||||
m.m.RUnlock()
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user