Skip to content

Commit

Permalink
audio, audio/vorbis: ignore error at the initial Seek
Browse files Browse the repository at this point in the history
This mitigates the issue of non-seekable source. At least,
vorbis.DecodeF32 and audio.NewPlayerF32 works.

Updates #3192
  • Loading branch information
hajimehoshi committed Feb 10, 2025
1 parent 38f370f commit 6cdc2a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion audio/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ func newTimeStream(r io.Reader, seekable bool, sampleRate int, bitDepthInBytes i
// Get the current position of the source.
pos, err := s.r.(io.Seeker).Seek(0, io.SeekCurrent)
if err != nil {
return nil, err
// Ignore the error, as the undelrying source might not support Seek (#3192).
// This happens when vorbis.Decode* is used, as vorbis.Stream is io.Seeker whichever the underlying source is.
pos = 0
}
s.pos.Store(pos)
}
Expand Down
10 changes: 10 additions & 0 deletions audio/vorbis/vorbis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func TestNonSeeker(t *testing.T) {
if got, want := s.SampleRate(), audioContext.SampleRate(); got != want {
t.Errorf("s.SampleRate(): got: %d, want: %d", got, want)
}

// TODO: Check the result of io.ReadAll (#3192).
}

func TestNonSeekerF32(t *testing.T) {
Expand All @@ -150,4 +152,12 @@ func TestNonSeekerF32(t *testing.T) {
if got, want := s.Length(), int64(0); got != want {
t.Errorf("s.Length(): got: %d, want: %d", got, want)
}

buf, err := io.ReadAll(s)
if err != nil {
t.Errorf("io.ReadAll: %v", err)
}
if len(buf) == 0 {
t.Errorf("len(buf): got: %d, want: > 0", len(buf))
}
}

0 comments on commit 6cdc2a6

Please sign in to comment.