audio/vorbis: Accept io.Reader instead of io.ReadSeeker

Closes #1621
This commit is contained in:
Hajime Hoshi 2021-04-24 16:41:20 +09:00
parent 68d24f1c62
commit e62eba387d

View File

@ -116,7 +116,7 @@ func (d *decoded) Length() int64 {
}
// decode accepts an ogg stream and returns a decorded stream.
func decode(in io.ReadSeeker) (*decoded, int, int, error) {
func decode(in io.Reader) (*decoded, int, int, error) {
r, err := oggvorbis.NewReader(in)
if err != nil {
return nil, 0, 0, err
@ -143,9 +143,11 @@ func decode(in io.ReadSeeker) (*decoded, int, int, error) {
//
// DecodeWithSampleRate automatically resamples the stream to fit with sampleRate if necessary.
//
// The returned Stream's Seek is available only when src is an io.Seeker.
//
// A Stream doesn't close src even if src implements io.Closer.
// Closing the source is src owner's responsibility.
func DecodeWithSampleRate(sampleRate int, src io.ReadSeeker) (*Stream, error) {
func DecodeWithSampleRate(sampleRate int, src io.Reader) (*Stream, error) {
decoded, channelNum, origSampleRate, err := decode(src)
if err != nil {
return nil, err
@ -174,10 +176,12 @@ func DecodeWithSampleRate(sampleRate int, src io.ReadSeeker) (*Stream, error) {
//
// Decode automatically resamples the stream to fit with the audio context if necessary.
//
// The returned Stream's Seek is available only when src is an io.Seeker.
//
// A Stream doesn't close src even if src implements io.Closer.
// Closing the source is src owner's responsibility.
//
// Deprecated: as of v2.1. Use DecodeWithSampleRate instead.
func Decode(context *audio.Context, src io.ReadSeeker) (*Stream, error) {
func Decode(context *audio.Context, src io.Reader) (*Stream, error) {
return DecodeWithSampleRate(context.SampleRate(), src)
}