mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
audio: Refactoring: Remove *player.start in JS
This commit is contained in:
parent
26bc94ca4a
commit
11141cc52a
@ -47,13 +47,27 @@ func startPlaying(src io.Reader, sampleRate int) error {
|
||||
return errors.New("audio: audio couldn't be initialized")
|
||||
}
|
||||
p := &player{
|
||||
src: src,
|
||||
sampleRate: sampleRate,
|
||||
bufferSource: nil,
|
||||
context: class.New(),
|
||||
src: src,
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user