audio: NewPlayerFromBytes now never returns errors

This commit is contained in:
Hajime Hoshi 2017-06-03 01:12:58 +09:00
parent 9a4a7fe5ba
commit 98c48463d2
3 changed files with 11 additions and 11 deletions

View File

@ -350,10 +350,15 @@ func NewPlayer(context *Context, src ReadSeekCloser) (*Player, error) {
//
// The format of src should be same as noted at NewPlayer.
//
// NewPlayerFromBytes returns error in the same situation of NewPlayer.
// NewPlayerFromBytes's error is always nil as of 1.5.0-alpha.
func NewPlayerFromBytes(context *Context, src []byte) (*Player, error) {
b := BytesReadSeekCloser(src)
return NewPlayer(context, b)
p, err := NewPlayer(context, b)
if err != nil {
// Errors should never happen.
panic(err)
}
return p, nil
}
// Close closes the stream. Ths source stream passed by NewPlayer will also be closed.

View File

@ -88,7 +88,8 @@ func (p *Player) updateSE() error {
if err != nil {
return err
}
return sePlayer.Play()
sePlayer.Play()
return nil
}
func (p *Player) updateVolume() {

View File

@ -87,10 +87,7 @@ func addNote(freq float64, vol float64) error {
// collects a *audio.Player object.
f := int(freq)
if n, ok := noteCache[f]; ok {
p, err := audio.NewPlayerFromBytes(audioContext, n)
if err != nil {
return err
}
p, _ := audio.NewPlayerFromBytes(audioContext, n)
if err := p.Play(); err != nil {
return err
}
@ -110,10 +107,7 @@ func addNote(freq float64, vol float64) error {
}
n := toBytes(l, r)
noteCache[f] = n
p, err := audio.NewPlayerFromBytes(audioContext, n)
if err != nil {
return err
}
p, _ := audio.NewPlayerFromBytes(audioContext, n)
if err := p.Play(); err != nil {
return err
}