-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix mp3.decoder.Len() when file size is unknown #37
Comments
Without testing this my hypothesis is that This needs to be handled and documented better at Beep's side. |
help!!! |
@lctech-daniel-hung, Could you elaborate a bit on what you need help with? |
I've also encountered this issue. I'm currently trying to parse the length of an MP3 to perform sampling, but the length is always zero. I'd like to ask if there have been any updates or fixes for this issue?" |
Do you pass an io.Seeker to the Decode function? To be honest this issue got away from me. But from the information I have now a "fix" would be an explicit error when trying to seek or get the length using a non-io.Seeker as a reader. Edit: if you need the duration of a reader which isn't seekable, it's possible to add it to a Some background info: it's not possible to get the length of an mp3 file without seeking or going through the whole file because the mp3 header doesn't encode the total duration of the file. Getting the duration is a bit of a manual process. |
Would it be more go-esque if instead of one Decode function there were 2? func Decode(rc io.ReadCloser) (s beep.StreamCloser, format beep.Format, err error) {}
func DecodeWithSeekAndLen(rc io.ReadSeekCloser) (s beep.StreamSeekCloser, format beep.Format, err error) {} I'm just thinking about solving the original issue but if your question is different in some way don't hesitate to reply @lctech-daniel-hung |
@MarkKremer |
edit: I've rewritten this comment so it's less had-a-long-day-brained. The benefit of having two functions is that we get compile-time checking. Currently, the I expect the number of variants to be dependent on the number of input Reader variants. We have The output type may differ depending on the Decoder. For example, mp3 needs an io.Seeker to be able to get the length of the audio, but some other types encode the length in the header so The function names in my earlier comment can be improved. Maybe |
That makes sense. Thanks for explaining. I'm alright with that approach it would be easier to manage as well. |
Started a proof of concept implementation in #132. I noticed that the I secretly hope that's just a bump in the road and it will figure itself out with some more refactoring... |
I've had this problem trying to stream mp3s, ended up just reloading the stream when it's finished buffering and starting it from the last position. Does go-mp3 already have a method that updates decoded buffer size? |
Could you explain what problem the larger buffer size would solve? A code snippet of what you're trying to do would be appreciated too. Also see my previous comment. Do these solutions work for you? Edit: It dawned on me that the original author may have just wanted to be able to decode a file without closing it. Although they also speak about reading from a byte slice so I'm a bit confused about this. Those are two problems that need different solutions in my opinion. |
I want to be able to play an mp3 before fully downloading it, and also be able to seek through it. The second part is where go-mp3s decode starts being a problem |
Thank you for your reply. That's indeed a limitation of go-mp3 but it has nothing to do with the buffer size. When a seeker is passed to it, it will enable the seek functionality, build a seek table and calculate the audio's length. In theory it should be possible to build the seek table on-demand to make your use-case possible, but it doesn't right now. The project has been archived also... Your example does make clear that the |
I'm trying to read an audio file through a reader from a
[]byte
array, but when I do this, the length of the output stream is0
. However, using the traditional method ofos.Open()
, the length is9589248
. Both methods can play the audio, but I can't use.Seek()
when using thebyte
array. I'm not sure what's wrong, any help would be appreciated.Original issue: faiface/beep#123
The text was updated successfully, but these errors were encountered: