Author Topic: Some mp3 file doesn't give out their duration if not fully playing  (Read 27 times)

scarboni

  • Posts: 47
Hello !

Currently, I have a playlist on my software. When the playlist is loaded, I use bass to get the duration of each files.
mp3, flac, and other works perfectly.

But, some mp3, does not gives out their duration, with the same code.
I have found out that if I record an mp3 with bass, this kind of mp3 will not allow to get their duration either.
Not while I'm not fully playing the file.

When I'm loading the playlist, I'm doing this, for every file on the playlist : (i've replaced the use of data by simple console.log, since it's not relevant in the issue logically)
Code: [Select]
    var chanTmp = BASS_StreamCreateFile(
      false,
      filepath,
      0,
      0,
      0
    );
    if (!chanTmp)
        console.log("error")

    var durationInBytes = BASS_ChannelGetLength(chanTmp, 0);
    durationInSeconds   BASS_ChannelBytes2Seconds(chanTmp, durationInBytes); //duration in seconds

    BASS_StreamFree(chanTmp);
    console.log(durationInSeconds)

If I finally play out the file from my playlist (so, I don't call Bass_StreamFree just after asking for length), I can get the duration. Maybe it has something to do with flags from create file ?
What I don't understand is that it works fine for most files, it's just with some mp3 files so far that it does not work. Always the same MP3 files, and not each MP3 files.

Thank you for your help ! :)

Ian @ un4seen

  • Administrator
  • Posts: 23619
I presume the missing "=" here is just a typo :)

Code: [Select]
    durationInSeconds   BASS_ChannelBytes2Seconds(chanTmp, durationInBytes); //duration in seconds

What is the return value from BASS_ChannelGetLength, ie. the "durationInBytes" value? MP3 files should always have some duration even if it isn't 100% accurate (eg. a VBR file without a header). If the duration is inaccurate rather than empty then adding the BASS_STREAM_PRESCAN flag to the BASS_StreamCreateFile call should fix that.

scarboni

  • Posts: 47
Yes, it's a typo ! I simplified my code to be easier to read on my post, and forgot this = :)

Annnnd, it was actually completely my fault, sorry for the faulty post...

I had the same issue earlier with Flac files, because I was lacking the flac plugin, since I loaded it, the issue have been solved on Flacs. And so, I naturally thought that this mp3 issue had something in common with it. But nope, 100% my fault here ! Thank you for helping pointing it out ! I wish you nice day :)