Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: beep.Loop2 and embedded music files #207

Closed
hanchon opened this issue Jan 27, 2025 · 1 comment
Closed

panic: beep.Loop2 and embedded music files #207

hanchon opened this issue Jan 27, 2025 · 1 comment

Comments

@hanchon
Copy link

hanchon commented Jan 27, 2025

Hi,

I was trying the lib and I found an issue with the new beep.Loop2 function while using MP3 files embedded in the code.

Here is the minimal replication

Basically the problem is related to the issue #37, where the .Len() of the file is returning 0 because the deprecated mp3 decoder does not handle correctly embedded files.

The program panics with the following message:

panic: invalid argument to Loop2; start position 0 must be smaller than the source streamer length 0

Using beep.Loop works fine with the mp3 decoder.

I am just opening the issue in case someone else ends up with the same issue, and the possible solution with the current state of the code is:

  • Use beep.Loop instead of beep.Loop2

UPDATE: I had a bug in my OGG example, beep.Loop2 also panics for that case.

@hanchon hanchon changed the title panic: beep.Loop2 and mp3 decoder panic: beep.Loop2 and embedded music files Jan 27, 2025
@hanchon
Copy link
Author

hanchon commented Jan 27, 2025

So the issue was just the io.NopCloser

file := io.NopCloser(bytes.NewReader(musicBytes))

Adding a no-op Close method to a bytes.Reader works fine:

type myReader struct {
	*bytes.Reader
}

func (f *myReader) Close() error {
	return nil
}

func NewMyReader(data []byte) *myReader {
	return &myReader{
		Reader: bytes.NewReader(data),
	}
}

...

file := NewMyReader(musicBytes)

@hanchon hanchon closed this as completed Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant