Minim icon indicating copy to clipboard operation
Minim copied to clipboard

sound.position() never reaches sound.length()

Open francescosoave opened this issue 6 years ago • 11 comments

Hi, I'm not sure if this is a bug of if I missed something however I see that the sound.position() value never reaches the sound.length(). Is this normal or not? I'm using Processing 3.1.1

basically I was trying to do the following but the condition will never become true

if(sound.position() >= sound.length()){
        sound.pause();

for instance these are the final values I get if I run println(sound.position() + " - " + (sound.length()))

7523 - 8072
7523 - 8072
7546 - 8072
7569 - 8072
7592 - 8072
7616 - 8072
7616 - 8072
7639 - 8072
7662 - 8072
7662 - 8072
7685 - 8072
7709 - 8072
7709 - 8072
7732 - 8072
7732 - 8072
7755 - 8072
7801 - 8072
7801 - 8072
7801 - 8072
7848 - 8072
7848 - 8072
7871 - 8072
7871 - 8072
7918 - 8072
7918 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072
7941 - 8072

francescosoave avatar Mar 05 '18 04:03 francescosoave

have any solutions?

yonghuming avatar Sep 21 '18 10:09 yonghuming

not from me I'm afraid

francescosoave avatar Sep 22 '18 13:09 francescosoave

it should work, but might be file-specific. i realize i've taken a very long time to respond to this, but if you could provide me with an example problem file, that'd be great.

ddf avatar Feb 23 '19 02:02 ddf

It would also be helpful to know which class sound is in this case.

ddf avatar Feb 23 '19 02:02 ddf

Hello, thanks for the reply. I was using mp3 files. I can't attach them here but I'm happy to send them over in whatever way is good for you.

sound is just sound = minim.loadFile("/data/samples/sample1.mp3");

francescosoave avatar Mar 02 '19 10:03 francescosoave

If you could possibly share them via Dropbox or something similar, that'd be fantastic.

ddf avatar Mar 02 '19 20:03 ddf

link

in order to have it working I was doing something like

if(sound.position() >= sound.length()-200){ //do stuff }

francescosoave avatar Mar 03 '19 16:03 francescosoave

Thanks, I was able to reproduce the issue with these files and should be able to dig into it later today or tomorrow.

ddf avatar Mar 03 '19 16:03 ddf

Ok, after looking into this for a bit, I've determined that the problem is that the length() of the files is being misreported due to how it is determined by Minim. In all cases the length is longer than it should be. This means that when playing normally, the end of the file is reached before position() is equal to length().

Attempting to fix this properly is going to take a while, I think, due to the fact that Minim still contains a hacky workaround for how it deals with mp3 metadata. It may also turn out that it's unfixable (or require a patched version of mp3spi), since my attempt at a quick fix is essentially the same as what mp3spi does internally, which means it might be the case that the mp3spi library will also report an incorrect length() for these files. It's not clear to me yet whether or not this is a bug, however.

In the meantime, if all you are doing is calling play() and then want to poll for when the file finishes playing, it should suffice to check isPlaying(), which will switch to false when it reaches the end of the file. At least this is what happens with current code.

ddf avatar Mar 04 '19 20:03 ddf

Also, is it OK if I include the mp3 files you shared in this repo as part of a test case?

ddf avatar Mar 04 '19 21:03 ddf

hi, thanks for the reply. yes you can include 2 of them (I don't own the rights for the percussion track)

francescosoave avatar Mar 05 '19 08:03 francescosoave