Recent

Author Topic: Taglib Pascal bindings?  (Read 2477 times)

Zoë

  • New Member
  • *
  • Posts: 28
Taglib Pascal bindings?
« on: February 14, 2017, 06:52:40 pm »
In an old thread, some posted this:

You can also try with taglib: https://taglib.github.io/
This lib is used by most popular multimedia players (I'm not sure but VLC and Rhythmbox are using it). I'm using it also, it  has headers for Free Pascal and is working great. The only one disadvantage that you must deploy taglib (dll / so) with your application (~2MB)

Does anyone know where I can find the headers they're talking about?  I can't find any other references to Pascal bindings online, and they're not included with the official taglib distribution.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Taglib Pascal bindings?
« Reply #1 on: February 15, 2017, 10:09:12 pm »
I ported C headers to pascal years ago using H2Pas. Don't know if they are still valid with current version but update them should be quite easy. Attached files. Remember that you first must load taglib_c and then taglib library, procedure LoadLibTag from taglib.pas do it for you. Here is simple example (PMusicTag is just pointer to pascal record, I'm pretty sure you get it):
Code: Pascal  [Select][+][-]
  1. function FillTag(ATag: PMusicTag): Boolean;
  2. var
  3.   pFile : PTagLib_File;
  4.   pTag : PTagLib_Tag;
  5.   pAudio : PTagLib_AudioProperties;
  6. begin
  7.   ATag^.Index := -1;
  8.   ATag^.Title := '';
  9.   ATag^.Artist := '';
  10.   ATag^.Album := '';
  11.   ATag^.Genre := '';
  12.   ATag^.Year := '';
  13.   ATag^.Length := 0;
  14.   ATag^.LengthS := '';
  15.   ATag^.Track := '';
  16.  
  17.   if not FileExistsUTF8(ATag^.Filename) then Exit(False);
  18.  
  19.   if not LibtagLoaded then
  20.   begin
  21.     LoadLibtag;
  22.     if not LibtagLoaded then
  23.       raise Exception.Create('Could not load libtag library');
  24.   end;
  25.  
  26.   taglib_id3v2_set_default_text_encoding(Ord(DefaultTagLibEncoding));
  27.   pFile := taglib_file_new(PAnsiChar(ATag^.Filename));
  28.   try
  29.     Result := taglib_file_is_valid(pFile);
  30.     if Result then
  31.     begin
  32.       //*** Tags ***
  33.       pTag    := taglib_file_tag(pFile);
  34.       ATag^.Title  := taglib_tag_title(pTag);
  35.       ATag^.Album  := taglib_tag_album(pTag);
  36.       ATag^.Artist := taglib_tag_artist(pTag);
  37.       ATag^.Genre  := taglib_tag_genre(pTag);
  38.       if taglib_tag_track(pTag) > 0 then
  39.         ATag^.Track := IntToStr(taglib_tag_track(pTag));
  40.       if taglib_tag_year(pTag) > 0 then
  41.         ATag^.Year := IntToStr(taglib_tag_year(pTag));
  42.  
  43.       //*** Audio property ***
  44.       pAudio      := taglib_file_audioproperties(pFile);
  45.       //FBitrate    := taglib_audioproperties_bitrate(pAudio);
  46.       ATag^.Length  := taglib_audioproperties_length(pAudio);
  47.       ATag^.LengthS := FormatPlayTime(ATag^.Length);
  48.     end;
  49.   finally
  50.     if Result then
  51.       taglib_tag_free_strings;
  52.     taglib_file_free(pFile);
  53.   end;
  54. end;
  55.  

 

TinyPortal © 2005-2018