audio/internal/readerdriver: Refactoring

This commit is contained in:
Hajime Hoshi 2021-05-09 05:46:55 +09:00
parent 22567d20b6
commit 7eeaef7ff8

View File

@ -96,7 +96,6 @@ type playerImpl struct {
err error err error
eof bool eof bool
cond *sync.Cond cond *sync.Cond
started bool
volume float64 volume float64
} }
@ -303,7 +302,6 @@ func (p *playerImpl) Play() {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueStart failed: %d", osstatus)) p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueStart failed: %d", osstatus))
return return
} }
p.started = true
p.state = playerPlay p.state = playerPlay
p.cond.Signal() p.cond.Signal()
@ -323,6 +321,10 @@ func (p *playerImpl) Pause() {
if p.state != playerPlay { if p.state != playerPlay {
return return
} }
if p.audioQueue == nil {
return
}
if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil { if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus)) p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus))
return return
@ -342,8 +344,10 @@ func (p *playerImpl) Reset() {
if p.state == playerClosed { if p.state == playerClosed {
return return
} }
if p.audioQueue == nil {
return
}
if p.started {
if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil { if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus)) p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus))
return return
@ -360,7 +364,6 @@ func (p *playerImpl) Reset() {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueFlush failed: %d", osstatus)) p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueFlush failed: %d", osstatus))
return return
} }
}
p.state = playerPaused p.state = playerPaused
p.buf = p.buf[:0] p.buf = p.buf[:0]