Recent

Author Topic: Reading MP3 Tags  (Read 1026 times)

winni

  • Hero Member
  • *****
  • Posts: 1992
Re: Reading MP3 Tags
« Reply #15 on: September 21, 2020, 10:27:52 am »
Hi!

Again: searching helps.

The topic was discussed in

https://forum.lazarus.freepascal.org/index.php/topic,49887.msg362880.html#msg362880


Winni

nikel

  • Full Member
  • ***
  • Posts: 123
Re: Reading MP3 Tags
« Reply #16 on: September 21, 2020, 11:37:52 am »
I give up. I'm going to use ffprobe/ffmpeg.

Bart

  • Hero Member
  • *****
  • Posts: 4030
    • Bart en Mariska's Webstek
Re: Reading MP3 Tags
« Reply #17 on: September 21, 2020, 12:04:31 pm »
I give up. I'm going to use ffprobe/ffmpeg.

Why?
With just 2 little fixes, your code seems to work.

Bart

wp

  • Hero Member
  • *****
  • Posts: 7727
Re: Reading MP3 Tags
« Reply #18 on: September 21, 2020, 12:20:57 pm »
I did not follow the thread in details, but maybe it is easier for you to apply a ready-made component: there is an ID3v2 component in JVCL. Open Online-Package-Manager, scroll down to JVCLLaz and check the packages jvcorelazr, jvcorelazd, jvmmlazr and jvmmlazd. Click install. When Lazarus has been recompiled the new component can be found on palette "JVCL Non-visual".

Here is a little console demo (a more complex, full GUI demo comes with the JVCL installation):
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, interfaces, jvID3v2;
  7.  
  8. const
  9.   FILE_NAME = 'YOUR_MP3_FILE';      // Replace this by the full path to your mp3 file.
  10. var
  11.   ID3v2: TJvID3v2;
  12.  
  13. function StripEOL(AString: String): String;
  14. begin
  15.   Result := AString;
  16.   while (Result <> '') and (Result[Length(Result)] in [#10, #13]) do
  17.     Delete(Result, Length(Result), 1);
  18. end;
  19.  
  20. begin
  21.   ID3v2 := TJvID3v2.Create(nil);
  22.   try
  23.     ID3v2.FileName := FILE_NAME;
  24.     ID3v2.Open;
  25.     WriteLn('Album: ', ID3v2.Texts.Album);
  26.     WriteLn('Artist: ', StripEOL(ID3v2.Texts.LeadArtist.Text));
  27.     WriteLn('Band: ', ID3v2.Texts.Band);
  28.     WriteLn('Orig Artist: ', StripEOL(ID3v2.Texts.OrigArtist.Text));
  29.     WriteLn('Title: ', ID3v2.Texts.Title);
  30.     WriteLn('Year: ', ID3v2.Texts.Year);
  31.     WriteLn('Genre: ', StripEOL(ID3v2.Texts.ContentType.Text));
  32.   finally
  33.     ID3v2.Free;
  34.   end;
  35.  
  36.   ReadLn;
  37. end.  
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018