Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:22:35+00:00 2026-05-30T18:22:35+00:00

I’m running into something when it comes to getting an MP3 ID3 v2 implementation

  • 0

I’m running into something when it comes to getting an MP3 ID3 v2 implementation going. I have it working for most part except for this one issue, which probably isn’t related to that at all. Anyhow, I’m using the below code to handle retrieving data of header tags that involve text.

What I’m running into is that (I guess?) I’m encountering Unicode characters in some different strings. I made the attempt to convert it below, and it works. But I’m getting $3F as a character ahead of the string and $3F$3F afterwards. Is there anything I can do to the code below to parse those out or would I have to do it myself? The files were encoded by ITunes if that helps any.

function Id3v2_string(currp: pointer; datasize: integer): string;
{ handles string processing for ID3v2 data }
  const
    IS_TEXT_UNICODE_UNICODE_MASK = $0F;
  var
    outstr: string;
    uscan: integer;
  begin
    outstr := '';
    SetLength(outstr, datasize);
    uscan := IS_TEXT_UNICODE_UNICODE_MASK;
    if IsTextUnicode(currp, datasize, @uscan) then
      outstr := WideCharToString(currp)
    else
      move(currp^, outstr[1], datasize);
    Result := outstr;
  end;

Note, I really am not interested in a media library for this since all I’m looking to do is edit ID3 tags and not play files – the implementation is already completed except for a few minor problems like this one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:22:36+00:00Added an answer on May 30, 2026 at 6:22 pm

    Depending on which version of ID3 v2 is being used, text strings may or may not be preceeded with a byte to tell you the actual encoding of the string. Don’t use IsTextUnicode() to guess what the encoding is (especially since it can report false results).

    In ID3 v2 up to v2.3, there is no encoding byte, text is either ISO-8859-1 or UCS-2, and UCS-2 strings always start with a BOM so you know the byte ordering. For example:

    // prior to Delphi 2009 - String is Ansi
    function Id3v2_string(currp: Pointer; datasize: Integer): String; 
    var
      W: WideString;
      I: Integer;
      Ch: WideChar;
    begin 
      Result := '';
      if (datasize >= SizeOf(Word)) and ((PWord(currp)^ = $FEFF) or (PWord(currp)^= $FFFE)) then begin
        // UCS-2 with BOM
        W := WideCharLenToString(PWideChar(Integer(currp) + SizeOf(Word)), (datasize - SizeOf(Word)) div SizeOf(WideChar)); 
        if PWord(currp)^ = $FFFE then begin
          // BE, convert to LE
          for I := 1 to Length(W) do begin
            Ch := W[I];
            W[I] := WideChar(((Word(Ch) and $FF) shl 8) or (Word(Ch) shr 8));
          end;
        end;
      end else begin
        // ISO-8859-1
        I := MultiByteToWideChar(28591, 0, PAnsiChar(currp), datasize, nil, 0);
        if I > 0 then begin
          SetLength(W, I);
          MultiByteToWideChar(28591, 0, PAnsiChar(currp), datasize, PWideChar(W), I);
        end;
      end;
      Result := TrimRight(W);
    end; 
    

    .

    // Delphi 2009+ - String is Unicode
    function Id3v2_string(currp: Pointer; datasize: Integer): String; 
    var
      Enc: TEncoding;
    
      function Convert(P: Pointer; Size: Integer): String;
      var
        Buf: TBytes;
      begin
        SetLength(Buf, Size);
        if Size > 0 then Move(P^, Buf[0], Size);
        Result := Enc.GetString(Buf);
      end;
    
    begin 
      Result := '';
      if (datasize >= SizeOf(Word)) and ((PWord(currp)^ = $FEFF) or (PWord(currp)^ = $FFFE)) then begin
        // UCS-2 with BOM
        if PWord(currp)^ = $FFFE then begin
          // BE
          Enc := TEncoding.BigEndianUnicode;
        end else begin
          // LE
          Enc := TEncoding.Unicode;
        end;
        Result := Convert(PWord(currp)+1, datasize - SizeOf(Word));
      end else begin
        // ISO-8859-1
        Enc := TEncoding.GetEncoding(28591);
        try
          Result := Convert(currp, datasize);
        finally
          Enc.Free;
        end;
      end;
    end; 
    

    ID3 v2.4 switches UCS-2 to UTF-16, and adds support for UTF-8 and UTF-16BE without a BOM, eg:

    // prior to Delphi 2009 - String is Ansi
    function Id3v2_string(currp: Pointer; datasize: Integer; Encoding: Byte): String; 
    var
      W: WideString;
      I: Integer;
      Ch: WideChar;
    begin 
      Result := '';
    
      case Encoding of
        $00: begin
          // ISO-8859-1
          I := MultiByteToWideChar(28591, 0, PAnsiChar(currp), datasize, nil, 0);
          if I > 0 then begin
            SetLength(W, I);
            MultiByteToWideChar(28591, 0, PAnsiChar(currp), datasize, PWideChar(W), I);
          end;
        end;
        $01: begin
          // UTF-16 with BOM
          SetString(W, PWideChar(Integer(currp) + SizeOf(Word)), (datasize - SizeOf(Word)) div SizeOf(WideChar));
          if PWord(currp)^ = $FFFE then begin
            // BE, convert to LE
            for I := 1 to Length(W) do begin
              Ch := W[I];
              W[I] := WideChar(((Word(Ch) and $FF) shl 8) or (Word(Ch) shr 8));
            end;
          end;
        end;
        $02: begin
          // UTF-16BE without BOM, convert to LE
          SetString(W, PWideChar(currp), datasize div SizeOf(WideChar));
          for I := 1 to Length(W) do begin
            Ch := W[I];
            W[I] := WideChar(((Word(Ch) and $FF) shl 8) or (Word(Ch) shr 8));
          end;
        end;
        $03: begin
          // UTF-8
          I := MultiByteToWideChar(65001, 0, PAnsiChar(currp), datasize, nil, 0);
          if I > 0 then begin
            SetLength(W, I);
            MultiByteToWideChar(65001, 0, PAnsiChar(currp), datasize, PWideChar(W), I);
          end;
        end;
      end;
      Result := TrimRight(W);
    end;
    

    .

    // Delphi 2009+ - String is Unicode
    function Id3v2_string(currp: Pointer; datasize: Integer; Encoding: Byte): String; 
    var
      Enc: TEncoding;
    
      function Convert(P: Pointer; Size: Integer): String;
      var
        Buf: TBytes;
      begin
        SetLength(Buf, Size);
        if Size > 0 then Move(P^, Buf[0], Size);
        Result := Enc.GetString(Buf);
      end;
    
    begin 
      Result := '';
    
      case Encoding of
        $00: begin
          // ISO-8859-1
          Enc := TEncoding.GetEncoding(28591);
          try
            Result := Convert(currp, datasize);
          finally
            Enc.Free;
          end;
        end;
        $01: begin
          // UTF-16 with BOM
          if PWord(currp)^ = $FFFE then begin
            // BE
            Enc := TEncoding.BigEndianUnicode;
          end else begin
            // LE
            Enc := TEncoding.Unicode;
          end;
          Result := Convert(PWord(currp)+1, datasize - SizeOf(Word));
        end;
        $02: begin
          // UTF-16BE without BOM
          Enc := TEncoding.BigEndianUnicode;
          Result := Convert(currp, datasize);
        end;
        $03: begin
          // UTF-8
          Enc := TEncoding.UTF8;
          Result := Convert(currp, datasize);
        end;
      end;
      Result := TrimRight(Result);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.