audio/mp3: Handle error when decoding

This commit is contained in:
Hajime Hoshi 2017-09-28 00:55:18 +09:00
parent fe2380f1ab
commit 1f051b50db

View File

@ -119,9 +119,12 @@ func Decode(context *audio.Context, src audio.ReadSeekCloser) (*Stream, error) {
case 2: case 2:
s.rightData = buf.Call("getChannelData", 1).Interface().([]float32) s.rightData = buf.Call("getChannelData", 1).Interface().([]float32)
default: default:
ch <- fmt.Errorf("audio/mp3: Number of channels must be 1 or 2 but %d", n) ch <- fmt.Errorf("audio/mp3: number of channels must be 1 or 2 but %d", n)
} }
close(ch) close(ch)
}, func(err *js.Object) {
ch <- fmt.Errorf("audio/mp3: decoding failed: %s", err.String())
close(ch)
}) })
if err := <-ch; err != nil { if err := <-ch; err != nil {
return nil, err return nil, err