⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpgtools.pas

📁 mp3 播放器 delphi 源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  { Always use this type for header variable declaration. If structure
    changes in future, this type will point to the newest version. }
  TMPEGDataCatalogue = TMPEGDataCatalogue1v1;

  { MPEGAUDIODATAFILE v1.1 header for Order form record definition. Same
    definition counts for v1.2 header. Do not use this type directly.
    Use TMPEGDataOrder instead.}
  TMPEGDataOrder1v1 = packed record
    CustomerID : string[15];
    Name : string[30];
    City : String[30];
    ZIP : String[10];
    Country : String[20];
    Address : String[30];
    Phone: String[15];
    Fax: string[15];
    Email: string[30];
  end;

  { Always use this type for header variable declaration. If structure
    changes in future, this type will point to the newest version. }
  TMPEGDataOrder = TMPEGDataOrder1v1;

  { Definition for structure of MPEG AUDIO DATA records. Do not use it
    directly. Use TMPEGDATA type instead. }
  TMPEGData1v2 = packed record
    Header : String3;        { Should contain "TAG" if header is correct }
    Title : String30;        { Song title  }
    Artist : String30;       { Artist name }
    Album : String30;        { Album  }
    Year : String4;          { Year }
    Comment : String30;      { Comment }
    Genre : Byte;            { Genre code }
    Track : byte;            { Track number on Album }
    Duration : word;         { Song duration }
    FileLength : LongInt;    { File length }
    Version : byte;          { MPEG audio version index (1 - Version 1,
                               2 - Version 2,  3 - Version 2.5,
                               0 - unknown }
    Layer : byte;            { Layer (1, 2, 3, 0 - unknown) }
    SampleRate : LongInt;    { Sampling rate in Hz}
    BitRate : LongInt;       { Bit Rate }
    BPM : word;              { bits per minute - for future use }
    Mode : byte;             { Number of channels (0 - Stereo,
                               1 - Joint-Stereo, 2 - Dual-channel,
                               3 - Single-Channel) }
    Copyright : Boolean;     { Copyrighted? }
    Original : Boolean;      { Original? }
    ErrorProtection : boolean; { Error protected? }
    Padding : Boolean;       { If frame is padded }
    FrameLength : Word;      { total frame size including CRC }
    CRC : word;              { 16 bit File CRC (without TAG).
                               Not implemented yet. }
    FileName : String255;    { MPEG audio file name }
    FileDateTime : LongInt;  { File last modification date and time in
                               DOS internal format }
    FileAttr : Word;         { File attributes }
    VolumeLabel : string20;  { Disk label }
    Selected : word;         { If this field's value is greater than
                               zero then file is selected. Value
                               determines order of selection. }
    Reserved : array[1..45] of byte; { for future use }
  end;

  { Definition for structure of old MPEG AUDIO DATA v1.1 records.
    Obsolete.  Used internaly to allow reading files of older MPEG AUDIO
    DATAFILE version. }
  TMPEGData1v1 = packed record
    Header : String3;
    Title : String30;
    Artist : String30;
    Album : String30;
    Year : String4;
    Comment : String30;
    Genre : Byte;
    Track : byte;
    Duration : word;
    FileLength : LongInt;
    Version : byte;
    Layer : byte;
    SampleRate : real;
    BitRate : LongInt;
    BPM : word;
    Mode : byte;
    Copyright : Boolean;
    Original : Boolean;
    ErrorProtection : boolean;
    CRC : word;
    FileName : String79;
    FileDateTime : TDateTime;
    FileAttr : Integer;
    VolumeLabel : string20;
    Selected : word;
    Reserved : array[1..48] of byte;
  end;

  { Old MPEG DATA record definition used in MPEGDATAFILE v1.0. Obsolete.
    Used internaly to allow reading of older MPEG AUDIO DATAFILE
    version. }
  TMPEGData1v0 = record
    Header : String[3];
    Title : String[30];
    Artist : String[30];
    Album : String[30];
    Year : String[4];
    Comment : String[30];
    Genre : Byte;
    Track : Byte;
    Duration : Word;
    FileLength : LongInt;
    Version : byte;
    Layer : byte;
    SampleRate : real;
    BitRate : LongInt;
    BPM : word;
    Mode : byte;
    Copyright : Boolean;
    Original : Boolean;
    ErrorProtection : boolean;
    CRC : word;
    FileName : string[79];
    ListName : string[79];
    FileDateTime : TDateTime;
    FileAttr : Integer;
    VolumeLabel : string[20];
    Reserved : array[1..50] of byte;
  end;

  { Current definition for MPEG AUDIO DATA structure. This type will
    point to newest record definition in case of future changes.

    MPEG AUDIO DATA is basic structure. It consists of data read from
    MPEG TAG and MPEG HEADER of MPEG AUDIO FILE. }
  PMPEGData = ^TMPEGData;
  TMPEGData = TMPEGData1v2;

  (*

    MPEG AUDIO CLASS definition.

    This object contains data about single MPEG AUDIO FILE and methods
    for reading, manipulating and writing them back to file. It is based
    on TObject class which means it is not supposed to be used as
    component. Create this object runtime.

    Here is an short example:

    use MPEGTools;
    var
      MPEGFile : TMPEGAudio;

    begin
      { create object }
      MPEGFile := TMPEGAudio.Create;
      { load data for mp3 song }
      MPEGFile.FileName := 'mysong.mp3';

      { read data }
      TitleEditBox.Text := MPEGFile.Title;
      ArtistTextBox.Text := MPEGFile.Artist;

      { change TAG data }
      MPEGFile.Title := TitleEditBox.Text;
      MPEGFile.Artist := ArtistEditBox.Text;

      { write changes to file }
      MPEGFile.WriteTag;

      { free }
      MPEGFile.Free;
    end;

    Heart of TMPEGAudio object is Data property which is actual record
    structure of TMPEGData. It is declared public which means you
    have full read and write access to it. That is not reccomended.
    Prefer using published properties. Data property is public because
    you may need easier access to whole record while dealing with lists,
    especially if you need writing such records in a file, like MPEG
    AUDIO DATAFILE is.

    To easy for you access and dealing with lists there is a function
    DataPtr which returns pointer to object's Data property.

    Public properties are mostly based on Data record but with some
    exceptions. You will find some properties read only for simple
    reason that you actually may not change all data read from MPEG
    file. We will not describe all properties but those which need
    attention.

    IsValid returns true if MPEG file is recognized as such. This is
    done by checking some fields values. Should be reliable.

    FileName has special function. When reading its value you will
    actually get value of TMPEGAudio.Data.FileName field. But, when you
    try to set value of this property, it will set
    TMPEGAudio.Data.FileName field but also read data from specified
    filename into Data record. Use this to actually read MPEG file.
    FileName will not automatically read data from MPEG file if AutoLoad
    property is False. You will have to use LoadData method to load data
    manually. Oposite to FileName, LoadData returns error value, so use
    it if you need to know if error occured right after loading file.

    Macro string may contain macros (you will find out about macros
    below) in string form explained before. Use this to convert
    macros if you do not need it to be changed often. Each time you
    change contents of this property it will automatically update
    contents of Text property. This should be used if you need to
    occasionally get converted macro but not to change macros. Actual
    conversion will be done for the first time you set macro string,
    and you may read it from Text property several times. This may
    speed up your application if you use it instead of calling
    Textilize method each time.

    Text property is updated whenever change occure in Macro property
    or other writable object properties, this field will be updated
    with converted contents of Macro property. Text property will be
    changed only when real change occures, and class takes care of
    that. You just have to read value when you need it.

    You also have some method functions available.

    IsValidStr takes two strings as parameters, and returns one of them
    depending of Boolean value of IsValid property. Use it when you need
    to display 'Yes' or 'No' or something similar based on this
    property.

    Similar functions are CopyrightStr, OriginalStr and
    ErrorProtectionStr. They are based on Copyright, Original and
    ErrorProtection properties respectively.

    GenreStr returns string description of Genre property. It is more
    appropriate for displaying than Genre number code.

    DurationTime is based on Duration property and returns value of
    TDateTime type. Since Duration is measured in seconds, we provided
    DurationTime function to easy you displaying values in minutes and
    seconds. We did not make it return string value since time format
    may differ from application to application. You may use Delphi's
    FormatDateTime function to get string value from DurationTime.

    ModeStr returns string description of MPEG channel mode (Mode
    property). It returns one of four values ('Stereo'/'Joint
    Stereo'/'Dual Channel'/'Single Channel'). If you need just
    'Mono'/'Stereo' identification you are on your own. Hint: only
    'Single Channel' mode is Mono.

    WriteTag function writes data from object to TAG of MPEG file.

    RemoveTag removes tag information form MPEG file. You will notice
    that by '[no tag]' value in properties which belongs to TAG and
    Header property will have value 'BAD' (which does not mean that MPEG
    file is BAD, but just that TAG is missing. If you want to check if
    MPEG file is correct, use IsValid property)

    Textilize is most powerful function in this object. You are provided
    with complex macro structure you can use to convert MPEG data values
    to strings. All you have to do is to call Textilize function and
    give it a string paameter containing macros. It will return string
    value with macros converted to actual MPEG data. You should also
    take a look of Macro and Text properties.

    Here are some macro examples:

    '%Author,T% %Title,T% %DurationForm,T%'
    '%Author%%Title%%DurationForm%'
    'Author: %A,T% * Title: %T,T% * Duration: %DF,T%'

    Use them in TAGEDitor demo application (Macro definition box) to see
    how it works.

  *)

type
  TOnReadError = function (const MPEGData : TMPEGData) : word;
  { function called when error occures while reading MPEG data from file.
    This function should show error to user and ask for Retry, Cancel,
    Ignore. User choice should be returned as function value (mrRetry,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -