audio: Refactoring: Remove *player.start in JS

This commit is contained in:
Hajime Hoshi 2016-04-04 02:23:15 +09:00
parent 26bc94ca4a
commit 11141cc52a

View File

@ -51,9 +51,23 @@ func startPlaying(src io.Reader, sampleRate int) error {
sampleRate: sampleRate,
bufferSource: nil,
context: class.New(),
positionInSamples: int64(p.context.Get("currentTime").Float() * float64(p.sampleRate)),
}
p.positionInSamples = int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
return p.start()
go func() {
defer p.close()
for {
err := p.proceed()
if err == io.EOF {
break
}
if err != nil {
// TODO: Record the last error
panic(err)
}
runtime.Gosched()
}
}()
return nil
}
func toLR(data []byte) ([]int16, []int16) {
@ -102,25 +116,6 @@ func (p *player) proceed() error {
return err
}
func (p *player) start() error {
// TODO: What if play is already called?
go func() {
defer p.close()
for {
err := p.proceed()
if err == io.EOF {
break
}
if err != nil {
// TODO: Record the last error
panic(err)
}
runtime.Gosched()
}
}()
return nil
}
func (p *player) close() error {
if p.bufferSource == nil {
return nil