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

📄 mpgtools.pas

📁 mp3 播放器 delphi 源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  function GetMPEGDurationComma (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGDurationMinutes (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGDurationMinutesComma (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGDurationForm (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLength (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLengthComma (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLengthKB (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLengthKBComma (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLengthMB (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGVersion (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLayer (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGLayerNr (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGSampleRate (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGSampleRateKHz (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGBitRate (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGErrorProt (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGErrorProtA (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGCopyright (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGCopyrightA (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGOriginal (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGOriginalA (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGMode (const MPEGAudio : TMPEGAudio) : string; far;
  function GetMPEGStereo (const MPEGAudio : TMPEGAudio) : string; far;
  function GetProgramVersion : string; far;
  function GetCurrentSystemDate : string; far;
  function GetCurrentSystemTime : string; far;

type
  { User defined function of TShowProgressFunc type may be used by unit
    to show progress of reading files. TagData is value of current MPEG
    DATA record.  Function may read any info from it. ListName is name
    of list. Counter shows current count of processed files, and
    MaxCount is number of files that will be processed. Form that
    displays progess should have Cancel button. Funtion should return
    False if user canceled progressing.

    We suggest you not to use this function to actually display progress
    form, but to change values of already openned form.

    Since this function will be usually called from loop, which may have
    large number of iterations, unit will release some time to let
    Windows process system messages. If it does not work correctly (if
    you cannot click Cancel button for instance), it is advisable for
    you to put Application.ProcessMessages call in your function.
  }
  TShowProgressFunc = function (const TagData : TMPEGAudio;
                                const ListName : string;
                                Counter : Integer;
                                MaxCount : Integer) : Boolean;

  { User defined function of TShowProgressError type may be used by unit
    to show error while processing. FileName is name of file which
    processing failed. This function will be called only when trying to
    load data from file. If file is Winamplist or MPEG DataFile it will
    be called only when error ocurrs openning that file, not files inside
    of it.

    Form should be modal and have Cancel, Retry, Ignore buttons. Function
    should return Modal result of form closing.
  }
  TShowProgressErrorFunc = function (const FileName : string) : Word;

  { User defined function of TShowExportProgressFunc will be used by
    unit to show export progress. It is similar to TShowProgrsFunc but
    with less input parameters.
  }
  TShowExportProgressFunc = function (const TagData : TMPEGAudio;
                                            Counter : Integer) : Boolean;


  { User defined function for comparing sorted items in list has input
    pointers to two compared items and returns 0 if items are equal,
    >0 if Item1 > Item2 or <0 if Item1 < Item2. Here are two types, one
    function, and the other object method. }
  TListSortCompare = function (Item1, Item2: Pointer): Integer of object;
  TListSortCompareFunc = function (Item1, Item2: Pointer): Integer;

  { User defined function for showin sort progress }
  TShowSortProgressFunc = procedure (currItem : Integer);

  { TSortMethod type defines sorting method used for TMPEGAudioList.
    smNone - list isnot sorted
    smInternal - list is sorted by internal rules (Artist+Title);
    smUser - List is sorted by user funtction assigned to
             UserSortCompareFunc property }

  TSortMethod = (smNone,smInternal,smUser);


  TSortDirection = (srtAscending, srtDescending);

  (*

  DEFINITION OF TMPEGAUDIO LIST CLASS

  Next issue to dealing with MPEG files is dealing with large number of
  MPEG files. This class should provide you simplified method to colect
  data about MPEG files and access them through list object. It
  inherites TObject class and expands it with specific methods and
  properies.

  TMPEGAudioList is not component. You should manually define variable
  of this type and create object by calling TMPEGAudioList.Create
  method.

  Main advantage is that you are free of allocating/releasing memory for
  MPEG record data and type casting. It uses TMPEGAudio class as basic
  data strucutre, thus allowing you to use all its properties and
  methods.

  You can add MPEG data in several ways:

    o by adding data from existing TMPEGAudio object (TMPEGAudioList.Add
      method),

    o by specifying MPEG filename (TMPEGAudioList.AddFile method),

    o by specifying WinAmp playlist (TMPEGAudioList.AddFromWinAmpList)

    o by specifying MPEG Datafile (TMPEGAudioList.AddFromMPEGDatafile)

  You can define custom functions which will be called on each iteration
  when importing or exporting data from several files or in case of
  reading error (ShowProgressFunc, ShowProgressErrorFunc and
  ShowExportProgressFunc properties).

  Also you can save data from list to file in WinAmp playlist
  (TMPEGAudioList.ExportToWinAmpList method), or MPEG Datafile
  (TMPEGAudioList.ExportToMPEGDatafile method).

  You can acces single items (MPEGAudio objects) through
  TMPEGAudioList.Items property. Current number of items can be obtained
  through TMPEGAudioList.Count method.

  If you need to determine type of some file, use
  TMPEGAudioList.GetfileType method. It can recognize MPEG Audio files,
  WinAmp playlists and MPEG datafiles. It may be useful when you alow
  browsing for all three file types a the same time.

  This is not finished class. For now, only basic methods are done, but
  I plan to do more especialy methods for sorting, dealing with
  duplicates and macros, selections etc... Your ideas are welcome.

  *)

  TMPEGAudioList = class (TList)
    private
      MPEGFile : TMPEGAudio;
      FShowProgressFunc : TShowProgressFunc;
      FShowProgressErrorFunc : TShowProgressErrorFunc;
      FShowMPEGAudioReadError : TOnReadError;
      FMPEGAudioUnknownArtist : string30;
      FMPEGAudioUnknownTitle : string30;
      FShowExportProgressFunc : TShowExportProgressFunc;
      FSortMethod : TSortMethod;
      FSortDirection : TSortDirection;
      FSortMacro : string;
      FUserSortCompareFunc : TListSortCompareFunc;
      FShowSortProgressFunc : TShowSortProgressFunc;
      FFileDetectionPrecision : Integer;
      function InternalSortCompareFunc (Item1, Item2: Pointer): Integer;
      function DoUserSortCompareFunc (Item1, Item2: Pointer): Integer;
      function FGetMPEGAudio(IndexNr : integer) : TMPEGAudio;
    public
      property ShowProgressFunc : TShowProgressFunc
               read FShowProgressFunc
               write FShowProgressFunc;
      property ShowProgressErrorFunc : TShowProgressErrorFunc
               read FShowProgressErrorFunc
               write FShowProgressErrorFunc;
      property ShowMPEGAudioReadError : TOnReadError
               read FShowMPEGAudioReadError
               write FShowMPEGAudioReadError;
      property MPEGAudioUnknownArtist : string30
               read FMPEGAudioUnknownArtist
               write FMPEGAudioUnknownArtist;
      property MPEGAudioUnknownTitle : string30
               read FMPEGAudioUnknownTitle
               write FMPEGAudioUnknownTitle;
      property ShowExportProgressFunc : TShowExportProgressFunc
               read FShowExportProgressFunc
               write FShowExportProgressFunc;
      property ShowSortProgressFunc : TShowSortProgressFunc
               read FShowSortProgressFunc
               write FShowSortProgressFunc;
      constructor Create;
      function Add (NewItem : TMPEGData) : Integer;
        { Add new item of TMPEGData type }
      function AddFromAnyFile (AnyFileName: string) : Integer;
        { Add informations from any type of file. It checks file
          type before loading and calls apropriate method. Returned
          value shows 0 if no error, -1 if file type is not recognized or
          error occured while reading file, -2 if user asked you to cancel
          operation }
      function AddFile (NewFileName : string) : Integer;
        { Add informations about single MPEG file. Return value is 0 if no
          error, -2 if user asked you to cancel whole operation and -1 for
          all other errors }
      function AddFromWinAmpList (PlayListName : string) : Integer;
        { Add informations from MPEG files listed in WinAmp list file.
          Return 0 if everything OK, -1 if error, and -2 if user
          canceled. }
      function ExportToWinAmpList (outfilename : string;
                                   ToAppend,
                                   RelativePath,
                                   ExportValid,
                                   SelectedOnly : Boolean) : Integer;
        { Export data to WinAmp type playlist. If ToAppend is true,
          append to existing file. If RelativePath, write file paths
          realtive to playlist path, If ExportValid then export data
          only for valid files. If SelectedOnly is true then only
          selected items will be exported. Return 0 if everything OK,
          -1 if error, and mrCancel if user canceled. }

      function AddFromPLSList (PlayListName : string) : Integer;
      function ExportToPLSList (outfilename : string;
                                ToAppend,
                                RelativePath,
                                ExportValid,
                                SelectedOnly : Boolean) : integer;

      function AddFromMPEGDatafile (DataFileName : string;
                                    var AppID : String;
                                    var HeaderStructType : byte;
                                    var HeaderStructLength : word;
                                    var HeaderStructPtr : pointer) : Integer;
        { Add informations from MPEG Audio Datafile to list. Reads
          Catalogues and Order Forms. Can recognize and load older file
          versions. Returns negative number if error reading file,
          mrNone if ok, and mrCancel if user cancels }

      function ExportToMPEGDataFile (outfilename : string;
                                     ToAppend,
                                     RelativePath,
                                     ExportValid,
                                     SelectedOnly : Boolean;
                                     AppID : string255;
                                     HeaderStructType : byte;
                                     HeaderStructLength : word;
                                     HeaderStructPtr : pointer) : Integer;
        { Export informations from list to MPEG Audio Datafile. If
          ToAppend is true, append to existing file. If RelativePath,
          write file paths relative to playlist path, If ExportValid
          then export data only for valid files. If SelectedOnly is true
          then only selected items will be exported. AppId is
          application id that should be stored to m3d header.
          HeaderStructType is type of header, HeaderStructLength is
          length of header in bytes and HeaderStructPtr is pointer to
          header data that should be stored to m3d file (Check m3d file
          structure document for details). Return 0 if everything OK,
          -1 if error, and mrCancel if user canceled. }

      procedure Clear;
        { Clear contents of the list }
      function Count : Integer;
        { Return number of items in the list }
      function SelectedCount : Integer;
        { Return number of selected items }
      procedure Delete (Index : Integer);
        { remove Item from the list by index }
      (* destructor Destroy; override;{ virtual; } *)
        { Destroy object }
      destructor Free;
        { Free memory allocated by object }
      property FileDetectionPrecision : Integer
        read FFileDetectionPrecision
        write FFileDetectionPrecision;
        { When attempting to recognize MPEG audio file, object will
          search through file trying to find two valid frame headers
          in a row. If file is correct, they will be found very fast,
          but if file is not MPEG then it will be searched up to it's
          end, and that may take a time. Setting this field to value
          greater than zero, you may specify number of bytes that
          should be searched. If object does not find proper headers
          in speified number of bytes, it will assume file invalid.
          If this prope

⌨️ 快捷键说明

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