• Welcome to PowerBasic Museum 2020-A.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Recent posts

#31
General Discussion / Re: mp3 duration
Last post by Juergen Kuehlwein - December 27, 2019, 11:38:49 AM
Yes, for compression formats with a variable bit rate like mp3 you cannot just divide the number of frames by the rate (fps). But you can calculate the exact duration by looping through the frames (i think this is what BASS_STREAM_PRESCAN does). There is sample code for this at various places in the net.

In the meantime i found what i was looking for. What an effort for a few lines of code! In fact retrieving the duration form the propertystore delivers correct results (even for mp3, Windows 7 and 10). I will post code here soon.
#32
General Discussion / Re: mp3 duration
Last post by Patrice Terrier - December 27, 2019, 10:32:14 AM
I think to remember from the top of my head that mp3 duration is only an approximation, because of the audio signal compression.
(mostly with mp3 using a variable bit rate)
The true length can be known only when audio comes to full completion.

This is the reason why Bass.dll use the BASS_STREAM_PRESCAN flag to return an accurate length.

What you could do is to encode the correct duration into the ID3 tag (there are many utilities able to do this).
Or convert the mp3 to ogg with Audacity if you don't need the ID3 tag.
#33
General Discussion / Re: mp3 duration
Last post by Juergen Kuehlwein - December 26, 2019, 10:04:23 PM
Thanks José,


good to know that there is a FreeBASIC equivalent. I already know how to do it (PB and FB). But the problem remains the same, IMediaSeeking GetDuration returns a wrong result for mp3 files. Seems i need a translation of Bob Carvers´s code for that.
#34
General Discussion / Re: mp3 duration
Last post by José Roca - December 26, 2019, 07:34:03 PM
You can look at my CAfxMp3.inc file, that includes de CAfxMp3 class. It gets the duration callig the GetDuration method of the IMediaSeeking interface. Be aware that this method returns 10,000,000 for a second (100-nanosecond units).

BTW I ported this class to FreeBasic (CDSAudio class in CDSAudio.inc).
Documentation: https://github.com/JoseRoca/WinFBX/blob/master/docs/COM/CDSAudio%20Class.md
#35
General Discussion / Re: mp3 duration
Last post by Juergen Kuehlwein - December 26, 2019, 06:35:21 PM
Finally i found what i need here (https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/775019-mp3-tagger-discussion , Bob Carvers code). It reads (at least i think it reads it) the correct duration, even if there are no ID3 tags.
#36
General Discussion / Re: mp3 duration
Last post by Juergen Kuehlwein - December 26, 2019, 05:28:02 PM
I know that the duration information displayed by Windows doesn´t come from ID3 tags, because, when i remove these tags (i verfied removal with a hex editor), the duration displayed stays the same. Mp3tag (a program for showing and editing id3 tags) shows the correct duration with and without tags in Windows 7 and 10. So there must be some other (working) method than Media foundation.
#37
General Discussion / Re: mp3 duration
Last post by Juergen Kuehlwein - December 26, 2019, 03:48:39 PM
In the meantime i found Jim Fritts´ PB source code (https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/773139-media-foundation-player) and could adapt it to show the duration - tada, now it´s correct.

Unfortunately the Media Foundation API seems a rather complicated way of retrieving this little piece of data and it requires Windows 8 or higher - i was hoping for an easier solution.
#38
General Discussion / Re: mp3 duration
Last post by Juergen Kuehlwein - December 26, 2019, 12:17:33 PM
Patrice,

Merry Christmas to you as well!

Thanks for your reply. I read about IMediaSeeking being a better choice, but for me (Windows 10), it returns the same (wrong) result as IMediaPosition. Strange that this bug hasn´t be fixed as of now and that you must do it yourself as your link proposes.

I know and already used Bass.dll (a great piece of software btw.), but i wanted to be independent of third party software. And obviously Windows can do what i want.
#39
General Discussion / Re: mp3 duration
Last post by Patrice Terrier - December 26, 2019, 10:23:24 AM
IMediaSeeking::GetDuration
and read this
https://support.microsoft.com/fr-fr/help/2676617/fix-the-imediaseeking-getduration-method-returns-an-incorrect-playback

Better to use Bass.dll, or the Media Foundation API.
#40
General Discussion / mp3 duration
Last post by Juergen Kuehlwein - December 26, 2019, 09:54:26 AM
Hi José,

Merry Christmas!


Found some time to play with my music collection. For playing mp3 files i use directshow, which works quite well for all music formats (.mid, .wav, .mp3, ...) - except for one thing, duration. I can get the time an audio file is expected to play from IMediaPosition or IMediaSeeking but in both cases the returned time is wrong for mp3 files. Interestingly enough Windows shows the correct time. The tooltip when hovering or the details tab of file properties (right click -> properties -> details tab) show the correct time.

So Windows somehow knows (or calculates) it. But how? How does Windows do that, and how can i make use of it? I cannot find an appropriate API nor am i able to find some COM code doing it. I found one thing, which looks promising here (https://docs.microsoft.com/de-de/uwp/api/windows.storage.fileproperties.musicproperties). I cannot find IStorageItemExtraProperties and related classes or interfaces in your includes. The required information might not be found in musicproperties but maybe in some other file property around here - this is my best bet.

Do you know how to retrieve these properties in PB?


Thanks,


JK